Skip to content

sudo command

Run commands as root or another user.

On this page

Syntax

sudo [options] command

Provided by the sudo package. Run man sudo for the full manual.

Common options

OptionWhat it does
-iRoot login shell
-sShell as root, keep your environment
-u USERRun as another user
-lList what you may run
-kForget the cached password
-EKeep your environment variables

Examples

  1. Run a command as root

    sudo apt update
  2. Open a root shell

    sudo -i
  3. Run as another user

    sudo -u www-data php artisan migrate
  4. Re-run the last command with sudo

    sudo !!
  5. List your sudo rights

    sudo -l
  6. Edit the sudoers file safely

    sudo visudo

Tips

  • Add users to the sudo group (Ubuntu) or wheel (RHEL) to grant sudo.

sudo guides

See all 11 guides that use sudo →

← All Linux commands · Suggest a fix

Back to top