Skip to content
Follow
Ubuntu Linux

How to Add a User to Sudoers in Ubuntu

Richard
Written by
Richard
Mar 17, 2026 Updated Aug 13, 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

Adding a user to the sudoers list in Ubuntu gives an ordinary account the power to run administrator commands. Ubuntu relies on this special permission system to let trusted people install software, change system settings, and fix problems without logging into the main root account.

The fastest way to grant this access is by running the `sudo usermod -aG sudo username` command in your terminal. This drops the account straight into the built-in sudo group, unlocking full system control.

⚡ 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 the execution of system-wide commands. This method permits software installation or file management, fitting everyday tasks requiring elevated permissions.

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 target account requires a logout and login cycle to apply the change. Alternatively, users can start a new login shell (a command-line session) to refresh permissions:

💻Code
su - username

Check the User’s Groups

To confirm membership within the sudo group, execute this command:

💻Code
groups username

The target user's name appears in the resulting output.

Test sudo Access

Switch to the target account and execute:

🐧Bash / Shell
sudo whoami

A password prompt followed by root output confirms operational sudo privileges.

Note: Receiving an error like "username is not in the sudoers file" indicates missing administrator privileges.

2Give User Custom sudo Permissions (Using sudoers File)

Custom command restrictions require editing the /etc/sudoers file directly. Manual file modification manages precise execution boundaries.

📝Important
Always use visudo for file edits. This utility checks syntax mistakes prior to saving, preventing broken configurations.

Open sudoers File Safely

In the terminal, run:

🐧Bash / Shell
sudo visudo

This command launches the sudoers configuration inside the default editor.

Preference for the nano text editor requires a specific command execution:

Granting full sudo access allows execution of any command with administrator rights. Sudo permissions derive from rules added to the special 'sudoers' file for targeted accounts. Executing the 'sudo' command enables powerful system actions once configuration completes.

The target account gains the ability to execute any command as the superuser via the `sudo` command. System authentication prompts for password verification during command execution as a core security measure.

Allow User to Run sudo Without Password

Editing the sudoers file located at /etc/sudoers permits passwordless command execution. Specific rules instruct the Ubuntu operating system to bypass password prompts during administrative tasks. This configuration accelerates workflow execution while lowering security parameters, demanding careful application.

⚠️Warning
Passwordless configurations decrease system security. Reserve this permission exclusively for automated tasks like scripts running on Ubuntu 22.04.
💻Code
username ALL=(ALL:ALL) NOPASSWD: /bin/mkdir, /bin/rmdir

Alternatively, enforcing password requirements for targeted utilities like apt and systemctl involves specific rules:

The `/etc/sudoers.d` folder in Ubuntu manages user permissions for running commands as administrator. Separate configuration files created inside `/etc/sudoers.d` replace direct edits to the main `/etc/sudoers` file. This structural method groups permissions, clarifying individual user capabilities.

To create a dedicated user file, run:

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

Appending custom rules requires syntax matching this example:

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

Tip: File names must exclude dots (.) and trailing tildes (~) to prevent system omission.

See What sudo Permissions a User Has

To audit permitted commands for a specific user, run this command:

🐧Bash / Shell
sudo -l -U username

Output displays permitted and restricted commands for the audited account.

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.

Managing Ubuntu administrator permissions involves group additions or custom edits within the primary sudoers file and the `/etc/sudoers.d` directory. Executing the 'visudo' utility catches syntax errors during file modification. Passwordless configurations demand extreme caution due to reduced security profiles.


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 *