Back to the command reference

sudo

SystemBeginner In real Linux

Run a command as the administrator (root)

Name: sudo = superuser do (also read as "substitute user do")

This command needs a real Linux system; you can practise it in real Linux mode.

Full man page

Description

sudo runs a command as root (or another user with -u), asking for **your own** password. Who may run what is defined in /etc/sudoers, which you should edit with visudo.

Compared with logging in as root it raises privileges only when needed and keeps a log, so it is safer. Your password is remembered for a while (15 minutes by default).

Syntax

sudo [OPTION]... COMMAND

Common options

-u / --user USERRun as another user
-i / --loginStart a root login shell
-s / --shellStart a shell as the target user (keeping your directory and environment)
-E / --preserve-envKeep your environment variables
-l / --listList what you may run
-v / --validateRenew the password timeout without running anything
-k / --reset-timestampMake the next sudo ask for the password again
-e / --editEdit files as root (like sudoedit, with your own editor)
!!(bash) Re-run the last command with sudo: sudo !!

Examples

  • $ sudo apt update

    Update package lists as root

    Explain
  • $ sudo -u postgres psql

    Run as the postgres user

    Explain

Related