How to make SSH go directly to specific directory?

This should work for you

ssh  -t second_machine "cd /very/long/path/to/directory/; bash"

Assumes you're wanting to run bash, substitute for a different shell if required.


To make it permanent, use RemoteCommand in your ~/.ssh/config file, e.g.

Host myhost
  HostName IP
  User ubuntu
  IdentityFile ~/.ssh/id_rsa
  RemoteCommand cd /path/to/directory; $SHELL -il

Related:

  • SSH Config File Alias To Get To a Directory On Server
  • How can I automatically change directory on ssh login?
  • Run a remote command using ssh config file

Tags:

Ssh

Directory