Skip to main content

sudo

The sudo (superuser do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy in the sudoers file. It temporarily elevates privileges without needing to log in as root.

Basic Syntax

sudo [OPTION]... COMMAND

Common Options

OptionDescription
-u userRun the command as the specified user instead of root.
-iRun a login shell as the target user (simulate initial login).
-sRun the shell specified by the SHELL environment variable.
-lList the allowed (and forbidden) commands for the invoking user.
-vValidate the user's cached credentials (extend the timeout).

Real-world Examples

  1. Run an administrative command:

    sudo apt update
  2. Edit a system file:

    sudo nano /etc/hosts
  3. Run a command as a different user (e.g., www-data):

    sudo -u www-data php script.php
  4. Start a root shell:

    sudo -i