Skip to the workspace
Pebellslearn by building
Shell and Other Basics  ›  Capstone Project

The Super User — root and sudo

Super User 12 minsudo runs a single command as root after checking your own password, while redirects and piped commands on the same line still run as you.

linux / The Super User — root and sudo

Explore each scene at your own pace.

01 · The rule

The rule

The Super User — root and sudo

Asha's garden club now runs a small server, and she needs to install a program and edit a file in /etc. Her normal account isn't allowed to do either, and that's deliberate. Linux keeps one all-powerful account, root, and makes you ask on purpose each time you need its power.

The rule

sudo lifts one command; the rest of the line is still you.

root is the administrator account, with user ID 0. It can read, change or delete anything, and the system doesn't ask whether you're sure. Logging in as root for everyday work is risky, so most systems give trusted users sudo instead:

$ sudo apt install tree
[sudo] password for asha:
  • sudo runs one command as root. It asks for your own password, not root's.
  • Only users listed in the sudo rules can use it, which usually means members of a group such as sudo or wheel. The rules live in /etc/sudoers, and you edit that file safely with visudo.
  • After you type your password, sudo usually doesn't ask again for a few minutes.
  • Each use can be logged, so there's a record of who did what.

Related commands:

Command Does
sudo command run one command as root
sudo -u ravi command run a command as another user
sudo -i open a root shell; exit leaves it
su - switch to root; needs root's password
sudo !! Bash: re-run your last command with sudo
whoami / id show who you are right now

A # at the end of the prompt usually means you're root, and $ means you're a normal user.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.