Linux – ssh and cd into current directory

linuxremotesshunix

When I ssh into mycomputer from logincomputer, I would like to automatically cd into the current directory (the one from which the ssh command was executed) on mycomputer. In particular:

> cd /tmp/

Now /tmp/ is the current working directory.

> ssh mycomputer
> cd /tmp

I would like this to happen automatically with 1 command. Is this possible? Assume the directory structure is exactly the same on both computers.

Best Answer

https://stackoverflow.com/questions/626533/how-can-i-ssh-directly-to-a-particular-directory

Answered on Stack Overflow.

ssh -t xxx.xxx.xxx.xxx "cd /directory_wanted"

You could add this into a shell script:

ssh -t xxx.xxx.xxx.xxx "cd \$PWD; bash"

Related Question