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.



ed wiget wrote:
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).
# Posted on 03-Feb-08 at 1:22 pm
Mich wrote:
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?
# Posted on 03-Feb-08 at 4:31 pm
fsdaily.com wrote:
Story added…
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…
# Posted on 03-Feb-08 at 10:56 pm
TBerben wrote:
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.
# Posted on 04-Feb-08 at 3:25 am
Jacob wrote:
Hmm.. maybe it was just Ubuntu that did that. I’ll have to change that in the article.
# Posted on 04-Feb-08 at 4:57 am
Free Gamer wrote:
Um… it’s a bit simpler than all that?
su -s -H
# Posted on 05-Feb-08 at 4:43 am
sudo与su(原创翻译) > 一阁Blog wrote:
[…] Original Posted at:http://fosswire.com/2008/02/03/sudo-vs-su/ […]
# Posted on 29-Mar-08 at 9:52 am
sudo与su(原创翻译) > 一阁Blog wrote:
[…] Original:http://fosswire.com/2008/02/03/sudo-vs-su/ […]
# Posted on 29-Mar-08 at 9:56 am