1. I can't edit the .bashrc of the fs I'm connecting to

  2. I have to use the ~/.ssh/config file

Here is my current config:

Host my-ssh
HostName <ip>
User <user>
IdentityFile <file location>
Compression yes
RemoteCommand cd <path to folder>

When I run ssh my-ssh nothing happens. The connection seems to automatically close. If I remove the RemoteCommand line it connects without an issue.

Is this something on the server config? It's an EC2 instance, either CentOS or RHEL and bash is the shell.

  • The list you've entered is in a desktop shortcut? man ssh to find out how to specify those items on a command line. Is this homework? – Xalorous Jan 23 '18 at 21:56

If you specify a remote command, then the ssh connection is going to close as soon as the remote command exits. A cd command will exit almost immediately.

A common way to do what you want is:

RemoteCommand cd /some/path && bash

(Substitute your desired shell in place of "bash"). This cd's to the path and then invokes a subshell if the cd operation succeeded. The ssh connection will close when the subshell exits.

You will also want to force ssh to allocate a PTY for the session:

RequestTTY yes

If you don't, then ssh won't request one by default, and you'll get a non-interactive shell session. Notably, you won't get a command prompt.


If you have a RemoteCommand specified it is the same as the following:

ssh user@host <command>

What happens is that ssh connects to the host, runs the command and exits, and returns the exit status of the command as the exit status of ssh.

From the man page:

If command is specified, it is executed on the remote host instead of a login shell.

So you are logging into the host, changing directory and then ssh is exiting. I doubt this is what you want. Remote command is non-interactive, i.e. to run one specific command on a remote machine.


Try to run ssh -t my-ssh. You may need to force pseudo terminal allocation which is ommitted by the config in ~/.ssh/config.

  • this is not complete, as the asker needs also to do something more than just issuing a cd ... (which then exits, ending the session) – thrig Jan 23 '18 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.