PDA

View Full Version : [all variants] Difference between sudo su and sudo -s



ItecKid
November 16th, 2008, 05:01 AM
Hello,

I am curious as to what the difference between sudo su and sudo -s are. As far as I can tell, they both make you root.

Thanks.

overdrank
November 16th, 2008, 05:13 AM
Hello,

I am curious as to what the difference between sudo su and sudo -s are. As far as I can tell, they both make you root.

Thanks.

Hi and according to the link
https://help.ubuntu.com/community/RootSudo
They are equivalent.

lovinglinux
November 16th, 2008, 05:34 AM
According to "man sudo"


-s The -s (shell) option runs the shell specified by the SHELL envi‐
ronment variable if it is set or the shell as specified in
passwd(5).

unutbu
November 16th, 2008, 05:43 AM
I did the following experiment:


applic@ion:~% sudo su
[sudo] password for applic:
root@ion:/home/applic# env > /tmp/sudo_su_env
root@ion:/home/applic# exit
exit
applic@ion:~% sudo -s
applic .bashrc read...
root@ion:~% env >/tmp/sudo_s

Here are the differences I found:

"sudo -s"
HOME=/home/applic
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
reads $USER's ~/.bashrc

"sudo su"
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
reads /etc/environment
reads /root/.bashrc


Notice the difference in $HOME. Being root and having $HOME set to the normal user's home can cause problems. For example, if you run a graphical app, the normal user's ~/.Xauthority can get overwritten by root. This causes the normal user problems later on such as not being able to run certain graphical apps through cron.

Here is a summary:


corrupted by user's
HOME=/root uses root's PATH env vars
sudo -i Y Y[2] N
sudo -s N Y[2] Y
sudo bash N Y[2] Y
sudo su Y N[1] Y


[1] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
probably set by /etc/environment
[2] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin


The bottom line, is "sudo -i" is the proper command to run when you want a root shell that is untainted by the user's environment.

bodhi.zazen
November 16th, 2008, 05:50 AM
+1 for sudo -i

While all these variations give you root access the differences are in the environmental variables as demonstrated by unutbu

If you really really want to know the technical details, you will need to read the man pages for su and sudo (because most of us would need to do just that to give you a better answer).

infoseeker
June 3rd, 2009, 08:36 PM
I noticed a problem the other day when using 'sudo -s' in that, as an example, when using 'mc' at the prompt, the resulting change in the mc's configuration file (in 'home/user/.mc') is owned by root, and not the user, and needs to be changed back to that of the user if further configuration changes are required when 'mc' is used as 'user'.

Using 'sudo -i' and then 'mc' uses the configuration file in '/root/.mc'.

theDaveTheRave
December 23rd, 2009, 10:57 AM
I just had a question related to this from my boss.

The quick easy answer was

Don't do < sudo su > or < sudo -i > to get a "true" root login. It open up your system to potential harm, and may cause viruses, trojan's etc to infect all the windows systems in the network. If you insist on using it, sit in front of the terminal, and pull the network cable out of the wall!

OK, this may not be particularly true, but it got the desired response of



Ah OK

Thanks


so our server should be safe for a few months... when hopefully my boss will remember there was a reason he doesn't use this option.

Personally I've never used the option... and I can quite happily break my system without it :lolflag:

David

jimingkui
December 23rd, 2009, 12:20 PM
Great! unutbu tells what exactly I want to know!

ashlynne
December 28th, 2010, 04:56 AM
Here is a summary:


corrupted by user's
HOME=/root uses root's PATH env vars
sudo -i Y Y[2] N
sudo -s N Y[2] Y
sudo bash N Y[2] Y
sudo su Y N[1] Y


[1] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
probably set by /etc/environment
[2] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin


The bottom line, is "sudo -i" is the proper command to run when you want a root shell that is untainted by the user's environment.

Hello there, this is my first post!

On my machine, doing sudo -i does not result in PATH being set to that of root's.


ceyi@ceyi:~$ sudo -i
root@ceyi:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games


Can anyone tell me why? What can I do to have it use root's PATH when I sudo -i?

@nne
March 8th, 2011, 08:43 PM
Hello there!

I hope people are around and willing to help me understand. This is what I get when I use "sudo -i", "sudo -s" and "sudo su" :



anne@anne-MaverickMeerkat:~$ sudo -i
[sudo] password for anne:
root@anne-MaverickMeerkat:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
root@anne-MaverickMeerkat:~# exit
logout
anne@anne-MaverickMeerkat:~$ sudo -s
root@anne-MaverickMeerkat:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
root@anne-MaverickMeerkat:~# exit
exit
anne@anne-MaverickMeerkat:~$ sudo su
root@anne-MaverickMeerkat:/home/anne# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
root@anne-MaverickMeerkat:/home/anne# exit
exit
anne@anne-MaverickMeerkat:~$
According to these results, I guess I should use "sudo -s" if I want to do a full backup of my system, for example, as described here : https://help.ubuntu.com/community/BackupYourSystem/TAR#Backing%20Up.

Has anyone any idea why there is a difference between my results and that of unutbu's? Or is it merely because I'm under 10.10?