# Linux commands: sudo

> Learn how the Linux sudo command runs a command as root using your own password, how sudo -i opens a root shell, and how -u runs it as any other user.

Author: Flavio Copes | Published: 2020-09-21 | Canonical: https://flaviocopes.com/linux-command-sudo/

`sudo` is commonly used to run a command as root.

You must be enabled to use `sudo`, and once you do, you can run commands as root by entering your user's password (_not_ the root user password).

The permissions are highly configurable, which is great especially in a multi-user server environment, and some users can be granted access to running specific commands through `sudo`.

For example you can edit a system configuration file:

```bash
sudo nano /etc/hosts
```

which would otherwise fail to save since you don't have the permissions
for it.

You can run `sudo -i` to start a shell as root:

![Terminal showing sudo -i command prompting for password and changing prompt to root#](https://flaviocopes.com/images/linux-command-sudo/Screen_Shot_2020-09-03_at_18.25.50.png)

You can use `sudo` to run commands as any user. `root` is the default, but use the `-u` option to specify another user:

```bash
sudo -u flavio ls /Users/flavio
```

> The `sudo` command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
