Skip to main content

sudo

Pronunciation
SOO-doo
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/sudo

In short

sudo lets a permitted user run a single command with root's or another user's privileges, after confirming their own password, and logs what was run.

What is sudo?

On Linux, macOS and other Unix-like systems the root user can do anything, so working as root all the time is risky: one mistyped command can damage the whole system. With sudo you work as an ordinary user and raise your privileges only for the commands that need them, by putting sudo in front, as in sudo apt update. It asks for your own password, not root's, and then runs that one command as root.

Who may use sudo, and for which commands, is set in the sudoers file, /etc/sudoers. On many distributions the members of a group such as sudo or wheel may run anything, but rules can also be narrow, such as letting a deploy user restart one service and nothing else. The file is edited with visudo, which checks the syntax before saving, since a broken sudoers file can lock everyone out of administration. Every use is logged, so administrators can see who ran what.

Its name is usually read as superuser do, and with -u it runs a command as any user, as in sudo -u postgres psql. After you type your password, sudo remembers it for a few minutes, 5 by default, so a series of commands doesn't keep asking. sudo was first written around 1980 at SUNY Buffalo, and today it is why systems such as Ubuntu and macOS can keep the root account locked: administrators work through sudo instead.

Key takeaways

  • sudo runs one command with root's, or another user's, privileges.
  • It asks for your own password and logs every use.
  • The sudoers file, edited with visudo, says who may run what.
  • Working as an ordinary user and using sudo only when needed limits the damage of mistakes.

Example

Using sudo from the command linebash
apt update               # as an ordinary user: fails with "Permission denied"
sudo apt update          # asks for your password, then runs as root
sudo -u postgres psql    # run a command as another user
sudo -l                  # list what you are allowed to run
sudo visudo              # edit /etc/sudoers, with a syntax check before saving

Readers ask

What is the difference between sudo and su?

su switches to another account, usually root, and needs that account's password; you then stay root until you exit. sudo runs one command with raised privileges and needs your own password, so root's password never has to be shared and every command is logged.

Why does sudo say I am not in the sudoers file?

Your account hasn't been given sudo rights on that machine. An administrator can add you to the admin group, such as sudo on Ubuntu or wheel on Fedora, or add a rule for you to the sudoers file.

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings