su root和su - root的区别——建议使用su - root

 这两天在练习在linux虚拟机上配置监听器,但是一直报错,怀疑是HOST的设置有问题。
    
      当前HOST设置为主机名,我尝试着设为IP,因此使用su root切换到root下,使用ipconfig命令查询主机的IP地址,但是一直报错,非常纳闷儿,后来在朋友的提醒下,说应该执行 su - root(注意:减号前后都有空格)。果然如他所说,进去后命令顺利执行。
   
      下面是从网上查到的关于两者的解释:
su - root  is   the same as su -

just like login as root, then the shell is login shell,
which mean it will expericene a login process,
usually .bash_profile and .bashrc will be sourced

su  root    is    the same as su
like you open an interactive shell in root name,
then only .bashrc will be sourced.

     从中可以看出,区别就在于是否执行.bash_profile,也就是说su只能获得root的执行权限,不能获得环境变量;而su -是切换到root并获得root的环境变量及执行权限。

建议:
有些命令即使你使用su root切换到root用户,仍无法执行,所以切换到root用户时,建议使用su - root。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30162081/viewspace-1463280/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30162081/viewspace-1463280/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值