Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my Fedora 14 developer machine I can add a file to /etc/profile.d -- both my user and root user then have access to the shared aliases.

Switch over to remote CentOS 5.7 machine and what appears to be the exact same config, no dice, root user does not have access to the shared aliases.

This may be due to the fact that I SSH into the CentOS box, not sure. At any rate, the lame workaround has been to copy shared aliases into root user's .bashrc as it's the only way I've been able to get desired prefs into root (yes, I know I should sudo, but have been rolling with su for years).

Ideas appreciated, would prefer to not have to duplicate aliases if possible.

share|improve this question
What does /etc/bashrc on CentOS look like? – quanta Oct 15 '11 at 17:31
appears to be the same as on fedora, thus the question. Must have to do with diff between su-ing over ssh vs when logged directly into machine – virtualeyes Oct 15 '11 at 18:25
Do you mean it didn't work when logging as normal user and switching to root? If so, what command did you use? – quanta Oct 16 '11 at 9:49
Yes, ssh'ing into remote CentOS box and su'ing does not work. So, ssh me@there; dice, /etc/profile.d/ alias file not picked up. I could chuck everything into /etc/bashrc, but OS updates will blow it away, not to mention being a bit of an ugly solution. Anyway, works fine logged into local machine, so must be diff. between ssh and local login (unless someone in the know would like to share the details ;-)) – virtualeyes Oct 17 '11 at 13:59
up vote 4 down vote accepted

Must have to do with diff between su-ing over ssh vs when logged directly into machine

I suspect that you execute the su command without dash (-), and if so, it will invoke an interactive non-login shell. Combine with you have only following in /root/.bashrc:

# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
    # Shell is non-interactive.  Be done now!

(not source /etc/bashrc)

whereas if you directly login or use su -, it will invoke a login shell, /etc/profile is read and will be execute.

To see which file is read with different shells, adding logs to all these files by executing the following commands as root:

echo "echo 'running /etc/bashrc'" >> /etc/bashrc
echo "echo 'running /etc/profile'" >> /etc/profile
echo "echo 'running /root/.bashrc'" >> ~/.bashrc

Create an test alias:

# echo "alias list='ls'" > /etc/profile.d/

Now, login as normal user and use su, you will see something like this:

$ su
running /root/.bashrc
bash-3.2# list
bash: list: command not found

and with su -:

$ su -
running /etc/profile
running /root/.bashrc
# list
total 226540
-rw-rw-r-- 1 root root     60148987 Apr  1  2011 3241948.flv
share|improve this answer
I am marking this as the answer due to the comprehensive explanation. Why I do not know, but now "su" without needing "-" loads the /etc/profile.d/shared-pref-file. Odd, but at any rate happy to have non-duplication of aliases. Thanks... – virtualeyes Oct 20 '11 at 7:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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