GO KALI FREE
User Management

sudo Linux Command

Executes a command with superuser (root) privileges.

What does sudo do?

Executes a command with superuser (root) privileges.

Syntax

sudo command

Practical example

sudo apt update

Questions about sudo

What does sudo stand for?

sudo stands for 'superuser do' or 'substitute user do'. It temporarily elevates your privileges to run commands as root.

How do I run a command as another user?

Use `sudo -u username command` to run a command as a different user. For example, `sudo -u www-data apache2ctl start`.

How do I get a root shell with sudo?

Use `sudo -i` or `sudo su` to start an interactive root shell. This is useful when you need to run multiple root commands.

How do I check my sudo permissions?

Use `sudo -l` to list all commands you are allowed to run with sudo. This shows what commands are permitted and with what restrictions.

How do I edit the sudoers file safely?

Always use `sudo visudo` to edit /etc/sudoers. It validates syntax before saving, preventing lockout from sudoers errors.

How do I run the last command as sudo?

Use `sudo !!` to repeat the last command with sudo privileges. This is a quick shortcut when you forgot to use sudo.

How do I set a timeout for sudo password?

Edit the sudoers file with `sudo visudo` and add `Defaults timestamp_timeout=10` to set a 10-minute timeout. Default is 5 minutes.

What is the difference between sudo and su?

`sudo` runs a single command as root using your password. `su` switches to another user entirely and requires that user's password.

Related User Management

su

Switches to another user account or the root user.

passwd

Changes the password for a user account.

id

Prints user and group IDs (UID, GID) for the specified or current user.

useradd

Creates a new user account on the system.

w

Displays who is logged in and what they are currently doing.

usermod

Modifies an existing user account (groups, shell, home directory, etc.).