I want to make a ssh-config, that automatically changes the folder after connecting. I heart of a possibility in the linux universe with the configuration in ssh-config-file. Something like this:

RemoteCommand cd /var/www/html/project-directory

Because of multiple projects on the same server I want to make different ssh-configs with only different of RemoteCommand to get into the right projectfolder.

ssh project-x

I tried this:

RemoteCommand cd /var/www/html/project-x

here I login, got the MOTD and get loged out directly.

and that:

RemoteCommand cd /var/www/html/project-x && exec bash --login

here I login, got the MOTD and freeze on this position.

My whole config looks like this:

Host customer
    User username
    Hostname project-x.example
    IdentityFile ~/.ssh/id_rsa_project-x
    RemoteCommand cd /var/www/html/project-x && exec bash --login
    #RemoteCommand cd /var/www/html/project-x

Is there a way to use RemoteCommand to change directories after login on apple terminal. I use /usr/local/bin/bash from Homebrew: /usr/local/Cellar/bash/5.0.11/bin/bash (not the zshell).

  • The shell that matters is what runs on the servers - what is it? – mmmmmm Apr 8 at 10:03
  • You have two RemoteCommand lines up there, which one is the one you've tried? Also cd ... && exec bash --login is pointless, the newly spawned bash will always start with the home directory of the user. – nohillside Apr 8 at 10:07
  • which bash (server) > /usr/bin/bash // how can I find out which bash that is? – MonTea Apr 8 at 10:28
  • I updated my question @nohillside – MonTea Apr 8 at 10:39

You must log in to answer this question.

Browse other questions tagged .