Results 1 to 10 of 10

Thread: Difference between sudo su and sudo -s

  1. #1
    Join Date
    Sep 2008
    Location
    RPI
    Beans
    52
    Distro
    Ubuntu 10.04 Lucid Lynx

    Difference between sudo su and sudo -s

    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.

  2. #2
    Join Date
    Feb 2007
    Beans
    24,961
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Difference between sudo su and sudo -s

    Quote Originally Posted by ItecKid View Post
    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.

  3. #3
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: Difference between sudo su and sudo -s

    According to "man sudo"

    Code:
    -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).

  4. #4
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Difference between sudo su and sudo -s

    I did the following experiment:
    Code:
    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:
    Code:
    				                     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.

  5. #5
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: Difference between sudo su and sudo -s

    +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).
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  6. #6
    Join Date
    Nov 2005
    Location
    South Africa
    Beans
    248
    Distro
    Kubuntu Development Release

    Re: Difference between sudo su and sudo -s

    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'.

  7. #7
    Join Date
    Feb 2007
    Location
    /home/paris
    Beans
    690
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Difference between sudo su and sudo -s

    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

    David
    Eee pc via Wubi install.
    evertying works straight out of the box

    My Launchpad page

  8. #8
    Join Date
    Apr 2009
    Beans
    45

    Re: Difference between sudo su and sudo -s

    Great! unutbu tells what exactly I want to know!
    ubuntuhandbook.org, yet another blog for ubuntu tutorials, howtos.

  9. #9
    Join Date
    Dec 2010
    Beans
    1

    Re: Difference between sudo su and sudo -s

    Quote Originally Posted by unutbu View Post
    Here is a summary:
    Code:
    				                     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.

    Code:
    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?
    Last edited by ashlynne; December 28th, 2010 at 04:58 AM.

  10. #10
    Join Date
    Jan 2011
    Location
    Paris, France
    Beans
    10
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Difference between sudo su and sudo -s

    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" :

    HTML Code:
    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/Ba...R#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?
    Last edited by @nne; March 8th, 2011 at 08:47 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •