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:sudoruns 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
sudoorwheel. The rules live in/etc/sudoers, and you edit that file safely withvisudo. - After you type your password,
sudousually 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.