Linux :: /etc/profile.d中的共享别名未应用于root用户,为什么?

前端之家收集整理的这篇文章主要介绍了Linux :: /etc/profile.d中的共享别名未应用于root用户,为什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的Fedora 14开发人员计算机上,我可以将一个sharedAliases.sh文件添加到/etc/profile.d – 我的用户和root用户都可以访问共享别名.

切换到远程CentOS 5.7机器,看起来完全相同的配置,没有骰子,root用户无法访问共享别名.

这可能是因为我通过SSH进入CentOS盒子,不确定.无论如何,蹩脚的解决方法是将共享别名复制到root用户的.bashrc中,因为这是我能够获得所需的prefs到root的唯一方法(是的,我知道我应该sudo,但是一直在用su滚动年份).

赞赏的想法,如果可能的话,宁愿不必复制别名.

解决方法

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

我怀疑你执行没有破折号( – )的su命令,如果是这样,它将调用一个交互式非登录shell.与你结合只有在/root/.bashrc中关注:

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

(不是源/ etc / bashrc)

而如果您直接登录或使用su –,它将调用登录shell,读取/ etc / profile并执行sharedAliases.sh.

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

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

创建测试别名:

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

现在,以普通用户身份登录并使用su,您将看到如下内容

  1. $su
  2. Password:
  3. running /root/.bashrc
  4. bash-3.2# list
  5. bash: list: command not found

和su – :

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

猜你在找的Linux相关文章