Linux ::共享别名/etc/profile.d不适用于root用户,为什么?

在我的Fedora 14开发人员机器上,我可以添加一个sharedAliases.sh文件到/etc/profile.d – 我的用户和root用户都可以访问共享的别名

切换到远程CentOS 5.7机器,看起来是完全相同的configuration,没有骰子,root用户不能访问共享别名。

这可能是由于我SSH进入CentOS框,不确定。 无论如何,蹩脚的解决方法是将共享别名复制到root用户的.bashrc中,因为这是我能够获得所需的首选项进入目录的唯一方法(是的,我知道我应该sudo,但已经与su年份)。

意见赞赏,宁愿不必重复别名,如果可能的话。

必须处理与ssh之间的差异,直接login到机器

我怀疑你执行su命令没有短划线( - ),如果是的话,它会调用一个交互式的非login shell。 结合你只有在/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 

(不是源/etc/bashrc

而如果你直接login或使用su - ,它会调用一个login shell,读取/etc/profile并且执行sharedAliases.sh

要查看使用不同的shell读取哪个文件,请以root身份执行以下命令,将日志添加到所有这些文件中:

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

创build一个testing别名:

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

现在,以普通用户身份login并使用su ,您将看到如下所示的内容:

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

su -

 $ su - Password: running /etc/profile running /root/.bashrc # list total 226540 -rw-rw-r-- 1 root root 60148987 Apr 1 2011 3241948.flv