HxHippy

sudo

Execute a command as another user (superuser)

Overview

Allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.

Syntax

sudo [OPTION]... COMMAND

Common Options

-u user, --user=user

Run the command as a user other than the default (root).

-g group, --group=group

Run the command with the primary group set to group.

-l, --list

List the allowed (and forbidden) commands for the invoking user on the current host.

-v, --validate

Update the user's cached credentials, extending the sudo timeout.

-k, --reset-timestamp

Invalidate the user's cached credentials. The next sudo will require a password.

-K, --remove-timestamp

Remove the user's timestamp file completely.

-s, --shell

Run the shell specified by the SHELL environment variable or the target user's default shell.

-i, --login

Run the shell specified by the target user's password database entry as a login shell.

-E, --preserve-env

Preserve the current user's environment variables.

-H, --set-home

Set the HOME environment variable to the target user's home directory.

Examples

$ sudo apt update

Executes the apt update command as the superuser.

$ sudo -u anotheruser ls /home/anotheruser

Lists files in anotheruser's home directory, as anotheruser.

$ sudo -l

Lists the commands the current user is allowed to run via sudo.

$ sudo -v

Extends the sudo password timeout.

$ sudo -k

Forces sudo to ask for a password next time it's run.

$ sudo -s

Starts a new shell as the superuser.

$ sudo -i

Starts a login shell as the superuser (simulates a fresh login).

$ sudo -E some_command

Executes some_command as superuser, preserving the current user's environment variables.

superuseradminelevateprivilegesrootsudoexecute as