Sudo and Su

You've probably seen one of these commands. Ubuntu users have seen more of sudo, while SUSE, Fedora, and Debian have used su more often. What exactly is the difference?

Both of the commands enable you to gain root access. The major difference is in how privileges are obtained.

Su


Su is a command that enables you to open a shell or login as another user. Run without any parameters, su assumes that you want to become root. When run, you will be prompted for a password. This password is the password of whoever you want to switch to. For example, if I want to become root, running su at a terminal will ask me for root's password. If I run su bill, I will need to type in bill's password.

Once a password has been entered, a shell will open as if you had logged in as the su'd user. Anything you run from it will appear to come from that user.

Sudo


On an Ubuntu system, running su by itself to become root won't yield any results. Root by default does not have a usable password, so there is no way you can type one in to gain privileges. This is where sudo comes in. Sudo enables you to run a single command as another user (normally root).

The major difference here is that you enter your own password instead of someone else's. This enables a system with multiple administrators to not have to share a single password. When run as sudo -s, a root shell will be opened, as with su.

Combining the Two


In most cases, su is available on any system, even if it cannot be used directly. Sudo, on the other hand, usually is only available for a Debian or derivative system. Because of these, there are several tricks we can accomplish on an Ubuntu system:

sudo su # same effect as sudo -s

In the example above, sudo is used to gain root privileges. Because of this, su is essentially run as root. When this happens, su does not require a password to be entered, so this can be used as an alternative to sudo -s.

Taking that example further:

sudo su bill # same effect as sudo -s -u bill

This would grant a shell as the user bill. Again, you only have to type in your own password.

There are a few more tricks out there that can be accomplished with sudo and su, but that's up for you to discover.

Avatar for jacob Jacob Peddicord - http://jacob.peddicord.net/

Jacob is a web developer, student, and programmer from Ohio. He is a staff member at the Ubuntu Forums and is most likely a fanboy of the distribution. He loves to write in code and words, play video games, and rant about topics most would have abandoned long ago. Jacob uses GNOME and is never seen running stable software, much to the demise of his laptop.

Home » Articles »

Discussion: Sudo and Su

  1. ed wiget (guest)

    # Posted on 03 February 2008 at 01:22 PM

    I have used linux for well over 10 years, and both su and sudo has been on each distro (starting with slackware, to redhat 5.2 - 8 (pre-fedora), to FC 1 - 3, to mandrake 6 - 8, debian, etc, to now gentoo the last 4 or 5 years). One thing I wanted to point out is that there is a difference in su and su - -- if you add the - to su, you also inherit the persons complete shell environment. Anyone can su as long as you know the account password you are su'ing to, whereas you can only sudo specific commands that you are authorized to run from the sudo config file (which can only be edited with visudo command).



  2. Mich (guest)

    # Posted on 03 February 2008 at 04:31 PM

    I have been using Debian for the past few years and su is always available. I have only used su, never touched sudo at all. :-)

    As far as I can remember, sudo is "brought to fame" by ubuntu.

    Maybe you are referring to ubuntu and not debian?



  3. # Posted on 03 February 2008 at 10:56 PM

    <strong>Story added...</strong>

    This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here:

    http://www.fsdaily.com/EndUser/Sudo_and_Su...



  4. TBerben (guest)

    # Posted on 04 February 2008 at 03:25 AM

    I recently installed Debian on my laptop and it did certainly ask me to set a root password. You probably referred to Ubuntu, which disables the root account by default.



  5. Jacob (guest)

    # Posted on 04 February 2008 at 04:57 AM

    Hmm.. maybe it was just Ubuntu that did that. I'll have to change that in the article.



  6. Free Gamer (guest)

    # Posted on 05 February 2008 at 04:43 AM

    Um... it's a bit simpler than all that?

    su -s -H



  7. # Posted on 29 March 2008 at 09:52 AM

    [...] Original Posted at:http://fosswire.com/2008/02/03/sudo-vs-su/ [...]



  8. # Posted on 29 March 2008 at 09:56 AM

    [...] Original:http://fosswire.com/2008/02/03/sudo-vs-su/ [...]



  9. Dave (guest)

    # Posted on 22 November 2008 at 01:50 AM

    It's Greek to me :o)

    I just downloaded VMWare player so I can see what Linux is like. I happened to download an Ubunto image and want to get to the "root" of things so I can change the "user" name..



Home » Articles » Sudo and Su