Warning! Try this on non-essential account first because if you make a mistake in the command you may lose an access to the remote system.
If you use keys for SSH login then you can change path by prepending command=
to before a key in ~/.ssh/authorized_keys
on your remote server. Example:
command="cd /var/www/websites ; /bin/bash -l" ssh-rsa AAA.....rest of the key
It is fine to generate and use multiple keys for the same user. One key on the server may contain the command the other may not - this way you select expected behaviour at login time. You can simply wrap it up with local ~/.ssh/config
:
Host websites-my-host
HostName <realhostname>
IdentityFile ~/.ssh/<key1> #on the server key with "command"
User webmaster
Host my-host
HostName <realhostname>
IdentityFile ~/.ssh/<key2> #on the server key without command
User webmaster
This is what will occur:
local$ ssh websites-my-host
webmaster@realhostname:/var/www/websites$ _
or:
local$ ssh my-host
webmaster@realhostname:~$ _