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:~$ _
.profileinstead of.bashrc, but it depends on your use case..profileis executed only for interactive logins (e.g. shell) but.bashrcis also executed for noninteractive logins (e.g. scp, rsync, etc.). Also, .profile is more likely to be called by shells which are not bash (e.g. zsh). – Phil Hord Mar 22 '17 at 17:37