# sudo

> A command that runs one line as the root user. It asks for your password first.

**Field:** Infrastructure  
**Category:** Linux & the Command Line  
**Also known as:** sudo Command, Superuser Do, Run as Root

## Think of it like

Think of it like asking a grown-up to reach the top shelf for you. You ask, and they check first.

## Definition

sudo runs one command with the power of the root user. You type sudo before the command. It asks for your own password, not the root password. Only users on an allowed list may use it. Each use is written to a log, so there is a record of who did what.

## Example

Jack needs to install a program on his server. He types sudo apt install nginx and enters his own password.

## Example code

```console
$ whoami
jack
$ sudo whoami
[sudo] password for jack:
root
```

The same command, run twice. With sudo in front, it runs as root.

## Why it matters

You get root power only when you need it. The rest of the time a typo stays small.

## Common mistake

Putting sudo in front of every command out of habit. Then files end up owned by root, and normal tools cannot touch them.

## Three principles

- **One command.** Root power for just that line.
- **Your password.** Not the root password.
- **Logged.** There is a record of each use.

## Related terms

- [Root User](https://learn.benibix.com/term/infrastructure/root-user)
- [User Group (Linux)](https://learn.benibix.com/term/infrastructure/user-group)
- [File Permissions](https://learn.benibix.com/term/infrastructure/file-permissions)
- [Advanced Package Tool (APT)](https://learn.benibix.com/term/infrastructure/apt)
- [Command Line](https://learn.benibix.com/term/infrastructure/command-line)

## Told apart from

- [sudo vs Root User](https://learn.benibix.com/compare/sudo-vs-root-user): People think sudo is the root user, and it is not. Root is an account that can change anything on the machine. sudo is a command that lets a normal user act as root for one line, after typing their own password. Each use is written to a log, so you can see who did what. Commands typed while logged in as root leave no such line.

## Taught in

- [Root User and sudo](https://learn.benibix.com/learn/infrastructure-linux/root-user-and-sudo): Linux CLI, 5/10
- [sshd_config and Fail2ban](https://learn.benibix.com/learn/infrastructure-ssh/sshd-config-and-fail2ban): SSH, 6/9

![On the left, Jack, a normal user, types a command with sudo in front. A checkpoint asks for Jack's own password and checks that he is on the allowed list. The command then runs as root, user 0, on the right, and a line is written to the log below.](https://learn.benibix.com/diagrams/inf3-sudo.svg)

---

Source: https://learn.benibix.com/term/infrastructure/sudo
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
