first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

sudo and su; combining sudo and su for Ubuntu/Debian systems; FOSSwire.com

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.

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

mod date: 2008-12-02T20:59:40.000Z