When I ssh into a remote server, I usually want to go to a specific folder rather than home.

To save lots of time use, the config file in the hidden .ssh folder.

#Change into .ssh

cd ~/.ssh

#Edit config file

vim config

#Add these settings:

Host server-name-and-folder-name
  HostName ip-address
  User user-name
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes  
  RemoteCommand cd folder-you-want-to go-into && exec $SHELL -l
    RequestTTY yes	 

Here’s a complete example - obviously the names and ip addresses have been changed to protect the innocent.

This would send batman to the docker folder in Gotham-city.

Host mac-server-docker-folder
  HostName 192.168.1.1
  User batman
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes  
  RemoteCommand cd projects/greatest-app/gotham-city/docker && exec $SHELL -l
    RequestTTY yes

Visit Emlekezik.com