CentOS Linux Server Guide

Linux Command Clinic

su, su root, su - root  and su -

 

Many Linux beginners confuse the su and su - command. According to decription  man pages,

 

su is change the effective user id and group id to that of USER.

 

 

"su" is equivalent to "su root"

 

"su -" is equivalent "su - root"
 

 


"su -" or "su - root"

when you use this command, you are given a new login shell from the Linux server, which is the same as you logout from the existing user and perform a fresh login. if you type "pwd", you will notice that you are in root directory /root. The environment path will be also change to root's environment.

 


"su" or  "su root"
if you "su" only then basically you just temporary  "borrow" the root permission without having all the root environment  setting.  You will notice that you are not having sbin path. Which means some root commands you issue at this environment might not work.

 

I would suggest  Linux beginner  always use su - to avoid unnecessary troubleshooting process

 


[jane@srv1 ~]$ whoami
jane
[jane@srv1 ~]$ pwd
/home/jane
[jane@srv1 ~]$ env | grep PATH
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/jane/bin

 


[jane@srv1 ~]$ su
Password:
[root@srv1 jane]# pwd
/home/jane
[root@srv1 jane]# env | grep PATH
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/jane/bin

 


[root@srv1 jane]# su root
[root@srv1 jane]# pwd
/home/jane
[root@srv1 jane]# env | grep PATH
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/jane/bin

 


[root@srv1 jane]# su - root
[root@srv1 ~]# pwd
/root
[root@srv1 ~]# env | grep PATH
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

 

[root@srv1 ~]# su - jane
[jane@srv1 ~]$ pwd
/home/jane
[jane@srv1 ~]$ su -
Password:
[root@srv1 ~]# pwd
/root
[root@srv1 ~]# env | grep PATH
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
 

 

 

 

 

 

 

Back to Linux Clinic



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy