Change default path for when I SSH in to CentOS server?

If you are using PAM for authentication, which is probably the most likely. As root head into /etc/passwd.

There you should see your username and path! Change it there and you are home free!

EDIT - Sorry it just occurred to me that you maybe didn't want to change your home folder. In that case, simply add:

cd /home

To the bottom of your .bashrc file!


The thing to remember is that ~/.ssh/environment is read before a shell or ssh command is spawned, so (for example) neither export nor $PATH make sense. You can only set environment variables (not run general shell commands) here.

If you grab the environment for a non-interactive ssh shell, then modify that, you should get what you want for non-interactive commands. For example:

$ ssh mylogin@myserver env

will give you what the ssh starts with on your server. If you write your ~/.ssh/environment file as:

PATH=/usr/local/bin

and rerun the above, you should get "bash: env: command not found". Good!

Now, build up your path explicitly, based on what it was at base from your system's sshd (i.e. the first "ssh .... env" call), for example (adding /usr/local/bin at the head):

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Note also that it is not useful to try to set the CWD in ~/.ssh/rc (which is run after ~/.ssh/environment is read, but before your ssh shell or command) as your shell will start (by default) in your home path.