Automate SSH login and create remote interactive shell programmatically
I am working from Mac OSX and am trying to create a script that will ssh user@host
and then change the working directory (cd) from a virtual server.
Googling indicated that it ssh -t user@host "command goes here"
would allow this, but when I enter cd /my/path
it says there is no such directory. It also forces me to leave the server. What's the best, easiest way to do this?
source to share
I am assuming the desired end result is a remote interactive shell in the desired target directory that you can interact with from your keyboard. If not, please clarify the question.
Force TTY with an argument -t
to ssh and create an interactive shell with an explicit call bash -i
:
ssh -t user@host "cd /my/path && exec bash -i"
Authentication scripts / automation - the road is already well moved (and thus redundant); see existing questions like Bash: Managing SSH for help on this.
source to share