I'm trying to get ssh
to automatically change to a particular directory when I log in. I tried to get that behaviour working using the following directives in ~/.ssh/config
:
Host example.net
LocalCommand "cd web"
but whenever I log in, I see the following:
/bin/bash: cd web: No such file or directory
although though there is definitely a web
folder in my home directory. Even using an absolute path gives the same message. To be clear, if I type cd web
after logging in I get to the right folder.
What am I missing here?
EDIT:
Different combinations of quotes/absolute paths give different error messages:
LocalCommand "cd web"
/bin/bash: cd web: No such file or directory
LocalCommand cd web
/bin/bash: line 0: cd: web: No such file or directory
LocalCommand cd /home/gareth/web
/bin/bash: line 0: cd: /home/gareth/web: Input/output error
This makes me think that the quotes shouldn't be there, and that there's another error happening.
Best Answer
cd is a shell builtin. LocalCommand is executed as:What you're looking to do can't really be accomplished via SSH; you need to modify the shell in some way, e.g. viabashrc/bash_profile
.<Editing almost a decade later...>
LocalCommand
isn't what you want, anyway. That's run on your machine.You want
RemoteCommand
. Something like this worked for me: