TechEarl

How to Give a User sudo Access on Linux

Grant sudo by adding a user to the sudo or wheel group, or with a sudoers drop-in, and how to scope it to specific commands instead of full root.

Ishan Karunaratne⏱️ 3 min readUpdated
Share thisCopied
Grant a Linux user sudo access via the sudo or wheel group or a sudoers drop-in, and scope it to specific commands instead of full root.

The clean way to grant sudo is to add the user to the admin group: sudo on Debian and Ubuntu, wheel on RHEL, Fedora, and Arch.

bash
sudo usermod -aG sudo deploy        # Debian / Ubuntu
sudo usermod -aG wheel deploy       # RHEL / Fedora / Arch
Root terminal adding a user to the sudo group with usermod -aG sudo, then sudo -lU deploy listing that the user may run all commands.
usermod -aG sudo adds the user to the admin group; sudo -lU confirms they may now run commands as root.

The -a (append) is essential, as covered in add a user to a group: plain -G would wipe their other groups. The user must log out and back in for the new group to apply.

Verify it

bash
sudo -lU deploy        # what is deploy allowed to run?

Once they log back in, sudo whoami from their account should print root.

Scope it instead of granting everything

Full membership in sudo/wheel means run-anything-as-root. Often you want less than that, for example "this person may restart nginx but not become root". Do that with a sudoers drop-in, edited through visudo:

bash
sudo visudo -f /etc/sudoers.d/deploy
code
# /etc/sudoers.d/deploy
deploy ALL=(ALL) /usr/bin/systemctl restart nginx, /usr/bin/systemctl status nginx

That grants exactly those two commands as root and nothing else. The format is user host=(runas) commands. Drop-in files in /etc/sudoers.d/ are the right place for this; never hand-edit the main /etc/sudoers directly.

Group the rule for a team

For several people, point the rule at a group (prefixed with %) instead of repeating it per user:

code
# /etc/sudoers.d/web-ops
%webops ALL=(ALL) /usr/bin/systemctl * nginx

Then add people to webops with usermod -aG. One rule, managed by group membership.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxsudosudoerswheelSecuritySystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts

How to List Users and Groups on Linux

List every user and group from /etc/passwd and /etc/group with getent, tell human accounts from system ones by UID, and see which groups a user belongs to.