Linux command list

sudo command: run one command as the administrator

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying sudo. Nothing here can touch your real files.
user@webterm:~/project$
 

sudo runs a single command with administrator rights. Learn exactly what changes, why it has no effect on `>`, and why `sudo tee` exists, by running the commands in a real terminal in your browser.

Updated: 2026-09-07

Syntax

sudo command

Runs that one command as the administrator (root).

Try it first

You are logged in as user.

$ whoami
user

System logs are not readable by an ordinary user.

$ cat /var/log/auth.log
cat: /var/log/auth.log: Permission denied

With sudo, they are.

$ sudo cat /var/log/auth.log
Sep  7 09:00:01 webterm sshd[456]: Accepted publickey for user from 192.168.1.10
Sep  7 09:14:22 webterm sudo:     user : COMMAND=/usr/bin/systemctl restart nginx

That log is itself the record of who ran what through sudo.

What actually changes

Only who runs that command.

$ sudo whoami
root
$ whoami
user

sudo whoami answers root, and the very next whoami is back to user. The elevation lasts exactly one command.

Reaching what you cannot touch

If the destination belongs to root, even a copy fails.

$ cp index.html /var/www/html/
cp: cannot create '/var/www/html//index.html': Permission denied
$ sudo cp index.html /var/www/html/
$ ls -l /var/www/html
total 4
-rw-r--r--   1  root  root     15  Sep  7 17:17  index.html

Files created through sudo belong to root. If you will want to edit one later, hand it back with sudo chown user:user file.

Services work the same way.

$ sudo systemctl restart nginx
$ systemctl is-active nginx
active

It does not apply to redirection

This is the classic trap.

$ echo '10.0.0.1 db' >> /etc/hosts
zsh: permission denied: /etc/hosts

Writing sudo echo '10.0.0.1 db' >> /etc/hosts changes nothing, because the >> is carried out by your shell; sudo only reaches echo. tee moves the writing into the elevated program.

$ echo '10.0.0.1 db' | sudo tee -a /etc/hosts
10.0.0.1 db
$ cat /etc/hosts
127.0.0.1 localhost
10.0.0.1 db

sudo tee -a is the standard way to add a line to a system file.

When you actually reach for it

sudo is what you type to touch something that is not yours.

SituationWhat to type
Read a system logsudo cat /var/log/auth.log
Restart a servicesudo systemctl restart nginx
Place a file where it is served fromsudo cp index.html /var/www/html/
Add a line to a system configecho "..." | sudo tee -a /etc/hosts
Install a packagesudo apt install tree

Things that trip people up

sudo stops at the command. Redirection (>, >>), the right-hand side of a pipe and ~ expansion are the shell's work. Nearly every "I used sudo and it still failed" is this.

Files made with sudo belong to root. Later you find you cannot edit your own deployment. Check the owner with ls -l and hand it back with chown when needed.

Read the target once more before pressing enter. With sudo in front, system files are within reach. For anything irreversible such as rm -rf, check the path with your finger on the screen first.

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

tee / chown / chmod / systemctl

Frequently asked questions

How is sudo different from su?
`sudo` elevates **one command**. `su` switches you into the other account and keeps you there. Borrowing the privilege only when you need it is safer, and it leaves a record of what was run.
Whose password does it ask for?
On a real machine, **your own** password, not root's. It is remembered for a few minutes afterwards. The terminal on this page skips the prompt.
I used sudo and still got Permission denied.
You were redirecting with `>` or `>>`. Redirection is done by your shell, which sudo never touches. Rewrite it as `... | sudo tee -a file`.
Typing sudo every time is tedious.
That is the point. Privilege applies only where you asked for it, so a typo cannot take the system with it. Keep `sudo su` for the rare cases that need it.
Is there a record of what I ran?
Yes. On a real machine `/var/log/auth.log` and friends record who ran what through sudo.