Sudo in Linux

The sudo command gives some admin privileges to non-admin users

Certain Linux applications require elevated privileges to run. Use the su command to switch to the superuser (root), or you can use the sudo command instead.

How It Works

Although they work differently, the sudo command is analogous to the confirmation prompt you sometimes see in Windows or macOS. When asked in those operating systems if you want to continue performing that specific action, you're met with a button to confirm that you want to run the action with elevated privileges, and at times you might even have to enter an admin's password.

Linux uses the sudo command as a wall between normal tasks and administrative ones, so that you have to confirm that you want to do whatever it is that the command will execute, and that you're authorized to perform the task. Even more similar is the run as command in Windows; like in Linux, the run as command works from the command line to launch a file with credentials from a certain user, often an admin.

sudo command syntax

If you're not sure if you're using sudo or su, look at the trailing character on the command line. If it's a pound sign (#), you're logged in as root.

About the Sudo Command

When you put sudo in front of any command in terminal, that command runs with elevated privileges, which is why it's the solution to privilege-related errors.

Sudo operates on a per-command basis. Features include the ability to restrict the commands a user can run on a per-host basis, copious logging of each command to provide a clear audit trail of who did what, a configurable timeout of the sudo command, and the ability to use the same configuration file on many different machines.

Sudo Command Example

A standard user without administrative privileges might enter a command in Linux to install a piece of software:

Superuser error in Ubuntu
dpkg -i software.deb

The command returns an error because a person without administrative privileges isn't allowed to install software. However, the sudo command comes to the rescue. Instead, the correct command for this user is:

Sudo dpkg command in Ubuntu
sudo dpkg -i software.deb

This time the software installs.

You can also configure Linux to prevent some users from using the sudo command.

Was this page helpful?