Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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")

share|improve this question

marked as duplicate by Falcon Momot, Michael Hampton Aug 4 '13 at 5:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 '13 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 '13 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 '13 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 '13 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 '13 at 22:13

1 Answer 1

up vote 3 down vote accepted

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.

~/.bash_profile
~/.bash_login
~/.profile

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
share|improve this answer
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 '13 at 23:02

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