Linux :: Shared aliases in /etc/profile.d not applied to root user, why?
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!
return
fi
(not source /etc/bashrc
)
whereas if you directly login or use su -
, it will invoke a login shell, /etc/profile
is read and sharedAliases.sh
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/test.sh
Now, login as normal user and use su
, you will see something like this:
$ su
Password:
running /root/.bashrc
bash-3.2# list
bash: list: command not found
and with su -
:
$ su -
Password:
running /etc/profile
running /root/.bashrc
# list
total 226540
-rw-rw-r-- 1 root root 60148987 Apr 1 2011 3241948.flv