Is it possible, for each host, to set initial directory where shell would cd into when logged in? (not home)

For example, I have a snippet in ~/.ssh/config

Host mybusiness
Hostname mybusines.com
User plone

And now I can ssh to this host with ssh mybusiness command, but always the first task I need to do is to type in the command cd /srv/www

2 Answers 2


For anyone coming across this question these days – if you're using OpenSSH 7.6 or later, you can use the RemoteCommand option like so:

Host mybusiness
    HostName mybusiness.com
    User plone
    IdentityFile ~/.ssh/mybusiness
    RemoteCommand cd /srv/www; bash -l
    RequestTTY yes

Note that both

  • bash -l/zsh -l/fish -l/etc., and
  • RequestTTY yes/force

are required to, in addition to executing cd, also actually open a login shell.

New contributor
max is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Moving the correct answer mark to this, as it seems to be now cleanly possible. Thank you for finding the answer after 13 years. Commented Jul 10 at 14:09

I don't think that's possible, but you could config your shell's init script at the server. If you use bash at the server, you could add this line to the end of ~/.bashrc at the server:

cd /my/initial/dir

Another option is to create a small script on your client for starting SSH-connections, which will run a remote command after login:

# This is the file "/home/myuser/bin/myssh":
ssh $1 "cd /my/initial/dir"

Run it like this:

# myssh mybusiness
  • Looks like there is no way around this without creating your own helper scripts :( I'll mark this as correct answer. Commented Feb 4, 2012 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .