hanki.dev

SSH straight into a specific directory

I often have to check some logs from a particular server. So far I've always just SSH'd into the server (ssh -l myusername xx.xx.xx.xx) and then manually entered into the logs directory (cd /dir/another/logs). Today I discovered a neat trick – you can SSH directly into your wanted directory!

ssh -l myusername -t xx.xx.xx.xx "cd /dir/another/logs ; bash --login"

The -l flag is just to specify custom username, you might not need it. If you wan't explanation for the rest of the params read this awesome StackOverflow answer.

Another great idea is to make an alias of that command, something like this:

alias ssh-myserver='ssh -l myusername -t xx.xx.xx.xx "cd /dir/another/logs ; bash --login"'

#terminal