sudo and su –

Both sudo and su are highly dangerous.

The sudo command is used to run a following command as the super-user. Think “super-user do.” It lets regular users do rootly thing, like:

sudo cat /etc/shadow

You’ll be prompted for a password: Your Password. Run the command this way, then try it without sudo.

If you’re given permission to run sudo, that means you are a sudoer. You can look into the file /etc/sudoers to see your configuration. By default it’s wide open. Diligent sysadmins will clamp down hard on what you’re allowed to do.

The su command is different. You don’t put su in front of another command, you run it by itself. There are several gotchas.

  • You’re going to have to have root’s password to proceed. You shouldn’t have it. Nobody but the top sysadmin should have it. So you shouldn’t be able to use su at all.
  • If you run the command su “naked” (without that following dash, or what we call a tick in the Unix world), lots of things still won’t work for you. That’s because you haven’t taken on root’s user profile, all those details including root’s PATH variable.
  • If you run the command correctly, that is, su – (su space tick), root’s user profile will be read into your current session, and you’ll easily be able to run commands that are otherwise “hidden.”
  • You can also su to other users:
su fred

You’ll have to either be root, orĀ  have fred’s password to do this.

And Now For Something Really Dangerous

On many systems, the root account is disabled from logging in. This is not a stupid idea. But you can get around this limitation with the command:

sudo su -

Consider this a drastic measure you’d take in an emergency only.