Linux – Change default directory when I SSH to server

linuxsshUbuntu

I was wondering if there is a way to change the default directory that I get put into after I SSH into my Ubuntu server.

99% of the time when I'm logging into my server, it is to access files within a specific directory:

/var/www/websites

Is there a config file that I can edit that will make sure I am put straight into this directory when I login?

Best Answer

There are three ways to achieve this:

  • add cd /var/www/websites to the end of your .bash_profile. This is executed only for interactive logins (e.g. ssh).
  • add cd /var/www/websites to the end of your .bashrc. I use this one on our puppetmasters as I always want to be in /etc/puppet/environments/dkaarsemaker there instead of my homedir :-)
  • Change your homedirectory on the server to /var/www/websites (this is not really a good idea)