Skip to main content
Controlling who can perform administrative tasks is crucial for system security. In this guide, you’ll learn how to grant and restrict sudo access on Linux, manage entries in /etc/sudoers, and apply fine-grained policies for different users and groups.

Using sudo

By default, only the root (superuser) can modify system-critical files and settings. Prefixing a command with sudo elevates it to root privileges:
When running sudo for the first time, you’ll be prompted for your password—not the root password.

Granting sudo via the wheel group

Many Linux distributions allow members of the wheel group to use sudo:
To add a user (e.g., trinity) to wheel:
Now trinity can execute any command with sudo, which is easy but lacks fine control.

Fine-grained control with /etc/sudoers

Instead of a broad group assignment, define precise policies in /etc/sudoers. Never edit that file directly! Always use visudo, which validates syntax.
Inside, you’ll find a line like:
A malformed /etc/sudoers can lock out all sudo access. Always use visudo to edit safely.

Breakdown of a sudoers entry

Defining custom sudoers policies

Below are sample entries to append near the end of /etc/sudoers via visudo:

Running commands as another user

Beyond root, you can invoke commands as any user:

Handling “Permission denied” errors

If a user invokes a disallowed command, sudo reports:

Disabling the password prompt

To let a user run commands without entering their password, add NOPASSWD::
Use NOPASSWD: sparingly; it increases convenience but may reduce auditability.

Watch Video

Practice Lab