Skip to content
Follow
Ubuntu Linux

How to Add a User to Sudoers in Ubuntu

Richard
Written by
Richard
Mar 17, 2026 Updated Sep 15, 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 uses this permission system to let trusted people install software, change system settings, and fix problems without logging into the main root account.

Advertisement

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 to give you 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.

Advertisement

1Add User to the sudo Group (Easiest Way)

To add user to sudoers Ubuntu the easiest way, you can place the user into the built-in sudo group using a simple terminal command. This grants them full administrator rights to install software and manage system files without needing to create custom configuration rules from scratch.

Step 1: Open the terminal.

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

sudo usermod -aG sudo username

Step 3: The target account requires a logout and login cycle to apply the change. Alternatively, start a new login shell (a command-line session) to refresh permissions:

Advertisement
su - username

Check the User’s Groups

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

groups username

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

Test sudo Access

Switch to the target account and execute:

sudo whoami

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

Advertisement
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.

📝ImportantAlways use visudo for file edits.

This utility checks syntax mistakes prior to saving, preventing broken configurations.

Open sudoers File Safely

You open the sudoers file safely in Ubuntu by running the visudo command in your terminal rather than opening the file in a standard text editor. This built-in tool checks your syntax for errors before saving, which prevents you from accidentally locking yourself out of administrator access.

sudo visudo

This command launches the sudoers configuration inside the default editor.

Advertisement

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

You allow a user to run sudo without a password in Ubuntu by adding a specific rule to the /etc/sudoers configuration file. This setup lets the user run administrative commands immediately without typing their password every time, though it reduces your system security.

Advertisement
⚠️WarningPasswordless configurations decrease system security.

Reserve this permission exclusively for automated tasks like scripts running on Ubuntu 22.04.

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:

Advertisement
sudo visudo -f /etc/sudoers.d/username

Appending custom rules requires syntax matching this example:

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:

sudo -l -U username

Output displays permitted and restricted commands for the audited account.

Advertisement

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 sudo permissions in Ubuntu involves adding users to the sudo group for quick administrative access or editing the sudoers file for custom rules. Always use visudo to prevent syntax mistakes, keep passwordless access to a minimum, and check user permissions regularly with the command line.


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.

Advertisement

📚 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 *