Skip to content
Follow
Ubuntu Linux

How to Add a User to Sudoers in Ubuntu

Richard
Written by
Richard
Mar 17, 2026 Updated Jul 12, 2026 4 min read
How to Add a User to Sudoers in Ubuntu
How to Add a User to Sudoers in Ubuntu
TaskCommand
Add user to sudo groupsudo usermod -aG sudo username
Check user groupsgroups username
See user’s sudo permissionssudo -l -U username
Edit sudoers file safelysudo visudo
Create sudoers file for usersudo visudo -f /etc/sudoers.d/username
Test sudo accesssudo whoami

Sudoers in Ubuntu lets you give a specific user permission to run commands with administrator power, like the main administrator (root). This means they can make system-level changes that regular users can’t.

The main way to grant this power is by adding a user to the built-in `sudo` group in Ubuntu. This gives them broad administrative access.

However, you can also use the `/etc/sudoers` file for more control. This lets you pick exactly which commands a user can run using `sudo`.

⚡ Quick Answer

Add a user to the ‘sudo’ group using the command `sudo usermod -aG sudo username`. This grants them administrator privileges to run commands as root. The user must log out and back in for the change to take effect.

1Add User to the sudo Group (Easiest Way)

Adding a user to the ‘sudo’ group in Ubuntu grants them administrator rights, allowing them to run commands that affect the whole system. This method permits users to install software or manage files, and it’s suitable for everyday tasks requiring system-wide changes.

Step 1: Open the terminal.

Step 2: Run this command, replacing username with the actual user’s name:

🐧Bash / Shell
sudo usermod -aG sudo username

Step 3: The user needs to log out and log back in for the change to take effect. Alternatively, they can start a new login shell:

💻Code
su - username

Check the User’s Groups

To confirm the user is in the sudo group, run this command:

💻Code
groups username

You should see the user’s name listed.

Test sudo Access

Switch to the user (if you’re not already) and run:

🐧Bash / Shell
sudo whoami

If it asks for a password and then shows root, sudo is working!

Note: If you see an error like “username is not in the sudoers file,” the user doesn’t have sudo rights.

2Give User Custom sudo Permissions (Using sudoers File)

Sometimes, you’ll want to control precisely which commands a user can execute using sudo. That’s when you edit the /etc/sudoers file.

📝Important
Always edit this file using visudo. It checks for mistakes before saving to prevent breaking sudo access.

Open sudoers File Safely

In the terminal, run:

🐧Bash / Shell
sudo visudo

This command opens the sudoers file in the default editor.

If you prefer the nano editor (which many users find more intuitive), run:

Giving a user full sudo access in Ubuntu means they can run any command with administrator rights. Sudo access is granted by editing the special ‘sudoers’ file to add a specific rule for that user. Once added, the user can use the ‘sudo’ command to perform powerful system actions.

The added user gains the ability to run any command as the superuser using the `sudo` command. When the user executes a command with `sudo`, the system will prompt for the added user’s password for verification, a security measure.

Allow User to Run sudo Without Password

You can allow a user to run sudo commands without typing their password in Ubuntu by editing the sudoers file, located at /etc/sudoers. Adding a specific rule tells the Ubuntu system not to ask for a password each time a sudo command runs. This passwordless sudo change makes running commands faster but reduces security, so use this setting with caution.

⚠️Warning
Allowing passwordless sudo reduces computer security. Use this permission only for automated scripts that require it, such as a script running on Ubuntu 22.04.
💻Code
username ALL=(ALL:ALL) NOPASSWD: /bin/mkdir, /bin/rmdir

Or, to require a password for specific commands like apt and systemctl:

The `/etc/sudoers.d` folder in Ubuntu manages user permissions for running commands as administrator. Instead of editing the main `/etc/sudoers` file, create a new, separate file within `/etc/sudoers.d` for each user’s specific rules. This organization method groups permissions, making it easier to see exactly what each user can do.

To create a file for a user, run:

🐧Bash / Shell
sudo visudo -f /etc/sudoers.d/username

Then add your rules inside, for example:

💻Code
username ALL=(ALL:ALL) NOPASSWD:ALL

Tip: The file name should not contain dots (.) or end with a tilde (~), or sudo will ignore it.

See What sudo Permissions a User Has

To check what commands a user can run with sudo, run this:

🐧Bash / Shell
sudo -l -U username

This shows a list of allowed and forbidden commands for that user.

Summary

  • Easy method: Add users to the sudo group to give full sudo access.
  • Control access: Edit the sudoers file or add files in /etc/sudoers.d for custom permissions.
  • Always use visudo: It prevents mistakes that could lock you out.
  • Be careful with passwordless sudo: It can make your system less safe.
  • Check sudo permissions regularly: Use sudo -l -U username to verify.

To manage sudo permissions in Ubuntu, you can add users to the ‘sudo’ group for full access. For custom control over sudo permissions, edit the main sudoers file or use the cleaner /etc/sudoers.d folder. Always use the ‘visudo’ command, which checks for errors, when editing sudoers files. Be very careful when allowing passwordless sudo, as it lowers security.


Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Open Windows Terminal as Admin Automatically
Windows How to Open Windows Terminal as Admin Automatically
Working with Sudo and Su Commands in Ubuntu Linux
Ubuntu Linux Working with Sudo and Su Commands in Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *