Skip to content

sudo and Root

Administrative commands need root. There are two ways to get it.

sudo

sudo runs one command as root. You type your own password, not root's. Only users in the sudo group (Ubuntu and Mint) can use it.

Try adding a user without it:

adduser archimedes
adduser: Only root may add a user or group to the system.

Now with it:

sudo adduser archimedes

You're asked for your password. Nothing appears as you type, not even dots; that's normal. Then adduser asks for the new user's password and some optional details. Press Enter to skip the details.

Usernames must be lowercase.

sudo remembers your password for a few minutes, so a second sudo right after won't ask again.

Becoming root

If you have a long series of admin commands, you can open a root shell:

sudo -i

The prompt changes from $ to #. Every command from now on runs as root with no further prompts. whoami says root; logname still shows who you really are.

adduser riemann
exit

exit takes you back to your own account. sudo su does nearly the same thing as sudo -i and you'll see it in older material.

Warning

A root shell has no safety net. A typo in rm -r deletes system files. Use sudo per command when you can, and exit a root shell as soon as you're done.

su

su (switch user) changes to another account, and asks for that account's password. su alone means root.

On Ubuntu and Mint, root has no password by default. That's a security feature: nobody can log in as root directly, and su to root doesn't work. sudo -i still works because it uses your password. Leave root's password unset unless the README tells you otherwise.

sudo -u alice command runs a command as alice instead of root.

Checking who has sudo

Everyone in the sudo group is an administrator. This is the Linux version of the Windows Administrators group, and just as important to audit.

getent group sudo

Remove someone who shouldn't be there:

sudo gpasswd -d username sudo

Also check /etc/sudoers and /etc/sudoers.d/ for entries that grant sudo outside the group. Edit /etc/sudoers only with sudo visudo, which checks the file for mistakes before saving. A broken sudoers file locks everyone out of sudo.

Confirm your new users

Open SettingsUsers on Ubuntu. archimedes and riemann are listed. Or from the terminal:

getent passwd archimedes riemann

Try it

  1. Add a user named testuser with sudo adduser.
  2. Open a root shell with sudo -i, run whoami and logname, then exit.
  3. Run getent group sudo and list who can use sudo on your machine.
  4. Delete the test user: sudo deluser --remove-home testuser.

Next

Users and Groups