on Centos 6.x,

I am adding some path export PATH=$PATH:/some/path

in both /etc/profile and ~/.bash_profile

but if it's not effective when I login via SSH

it only shows if I type source .bash_profile

What am I doing wrong?

(N.B. for logging via SSH I use the following alias: alias ssh-server='ssh -t user@server "cd /some/dir/ ; bash")

  • 1
    Since neither /etc/profile nor ~/.bash_profile is being read, it looks like you are using an interactive non-login shell. Only login shells read those files. However an interactive SSH session starts a login shell. Is your ~/.bashrc being processed?
    – Marco
    Aug 3, 2013 at 21:53
  • I just tested that if I add export PATH=$PATH:/some/path to ~/.bashrc, it actually gets added, but twice! what's going on?
    – Daniele B
    Aug 3, 2013 at 22:00
  • This confirms that you are runnnig an interactive non-login shell instead of a login shell. Are you logging in to the system and executing commands or are you providing a command as argument to ssh?
    – Marco
    Aug 3, 2013 at 22:03
  • I use ssh via this alias, which I copied from somewhere: alias ssh-server='ssh -t user@server "cd /some/dir/ ; bash"'. I am now wondering what's the meaning of that bash at the end, and whether is affecting something
    – Daniele B
    Aug 3, 2013 at 22:06
  • Why are you using that alias? If you want to change the directory, create an entry in .profile or .bashrc. If you want to change your shell, use chsh. If you want to save some typing, create a shorthand in .ssh/config.
    – Marco
    Aug 3, 2013 at 22:13

1 Answer 1


The reason your /etc/profile and ~/.bash_profile are not read is that you are not using an interactive login shell. A “normal” login, e.g. via

ssh myserver

creates an interactive login shell, in contrast to executing commands provided as argument to ssh, which use a non-login shell. An interactive non-login bash reads the files /etc/bash.bashrc and ~/.bashrc.

If you want to change the directory for interactive login shells, add your cd /some/dir to one of the following files. The first one found, is being processed, the others are ignored.


If your user name or host name is too long to type, create an alias in ~/.ssh/config:

Host server
HostName me.and.my.server.somedomain.tld
User daniele
  • 1
    thanks a lot Marco for the clear explanation! By the way, I found the way to execute commands as an argument of ssh and still have an interactive login shell, just by adding the --login parameter to the bash: ssh -t user@server "cd /some/dir/ ; bash --login"
    – Daniele B
    Aug 3, 2013 at 23:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.