9

I'd like to set ssh_config so after just typing ssh my_hostname i end up in specific folder. Just like I would type cd /folder/another_one/much_much_deeper/.

How can i achieve that?

EDIT. It's have been marked as duplicate of "How to ssh into dir..." yet it is not my question.

I know i can execute any commands by tailing them to ssh command. My question is about /ssh_config file not the command.

  • I've clarified my question. – Kazz Mar 29 '17 at 14:53
  • There's nothing about that in man ssh_config. The closest is LocalCommand but it cannot be used for interactive command. – lgeorget Mar 29 '17 at 14:54
  • 1
    Please could you explain (in your question) why you feel the change must be made to ssh_config? There are probably better places to configure the starting directory, and it would be helpful to understand why there is this particular restriction on a possible solution. – roaima Mar 29 '17 at 20:31
  • 1
    The fact "it can't be done in ssh_config" does not make this a duplicate of "do it in Bash". "You can't do that" is a perfectly valid answer. – Franklin Yu Oct 25 '17 at 18:54
  • 1
    @terdon However the fact "it isn't possible" may change over time. Yes, it is possible now. Now I (as well as anyone in future coming to see this) need a new answer, and we get stuck here. If this is not re-opened, I imagine that the desired path is to create a new question (and answer it)? – Franklin Yu Oct 26 '17 at 14:33
14

There wasn't a way to do that, until OpenSSH 7.6. From manual:

RemoteCommand

Specifies a command to execute on the remote machine after successfully connecting to the server. The command string extends to the end of the line, and is executed with the user's shell. Arguments to RemoteCommand accept the tokens described in the TOKENS section.

So now you can have

RemoteCommand cd /tmp && bash

It was introduced in this commit.

  • 3
    Add RequestTTY force if the remote command requires a TTY. For example: tmux new -As my-session – Aaron Blenkush Apr 13 '18 at 17:20
  • This is the killer ssh option Thanks! – nhed Feb 6 at 3:49
2

I'd like to set ssh_config so after just typing ssh my_hostname

It is not possible. There is no option to achieve that in ssh_config. The closest to it is setting up a bash alias or bash function, such as

myssh() {
    ssh -t $1 "cd /dir/; bash"
}
1

I responded on a different ticket before somoene had pointed out this was the original.

If using a mac, my recommendation is to use iTerm2 and create a profile. Put ssh my_hostname in the command line, and then add the command cd /folder/another_one/much_much_deeper/ in the send text at start field. When you connect to the sessions it will ssh to your hostname and cd to the directory in your case, or execute a command.

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.