Skip to content
Follow
Ubuntu Linux

How to Add a User to Sudoers in Ubuntu

Richard
Written by
Richard
Mar 17, 2026 Updated Oct 11, 2026 8 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. You need to be logged in as a user who already has sudo rights to do this. On a standard Ubuntu install, the first account created during setup already has them.

⚡ Quick Answer

Open Terminal and run sudo usermod -aG sudo username, replacing username with the account name. Have the user log out and back in for the change to take effect. Membership in the sudo group grants full administrator privileges.

Advertisement

1Add User to the sudo Group (Easiest Way)

To add a user to sudoers the easiest way, you place the user into the built-in sudo group using a single terminal command. Ubuntu’s default sudoers file already contains a rule that gives every member of this group full administrator rights. The user can install software and manage system files, and you don’t have to write any custom configuration rules.

  1. Open the terminal, either from the app menu or with the Ctrl+Alt+T shortcut. Make sure you are signed in as an account that already has sudo access.
  2. Run the command below, replacing username with the actual user’s name. Ubuntu asks for your own password, not the target user’s. Nothing appears on screen while you type it. That is normal.
🐧Bash / Shell
sudo usermod -aG sudo username

If the command succeeds, it prints nothing and returns you to the prompt. An error that says the user does not exist usually means a typo in the account name.

  1. Have the target user log out and log back in. Group membership is read when a session starts, so a session that was already open will not see the change. If you don’t want to log out, start a new login shell (a command-line session) with the command below to refresh permissions. This only affects that one terminal window.
💻Code
su - username

To undo the change later, remove the account from the sudo group again. The user then goes back to being a standard account after their next login.

Check the User’s Groups

Before you rely on the new access, check that the account really is in the group. To confirm membership within the sudo group, run this command:

Advertisement
💻Code
groups username

The target user's name should appear in the resulting output. If it doesn't, the previous step did not work. Check the spelling of the user name and run it again.

Test sudo Access

Membership in the group is not the same as a working sudo. Test it from the account itself.

  1. Switch to the target account, or log in as that user.
  2. Run the command below.
  3. Enter the user's own password when asked.
🐧Bash / Shell
sudo whoami

A password prompt followed by root output confirms that sudo privileges are working. If you see a message saying the user is not in the sudoers file, the user has not logged out and back in yet, or the group change did not apply.

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

2Give User Custom sudo Permissions (Using sudoers File)

The sudo group gives all-or-nothing access. If you want to limit a user to certain commands, you have to edit the /etc/sudoers file directly. Rules in that file let you set exactly which commands a user may run, and as which account.

Advertisement
📝ImportantAlways use visudo for file edits.

This utility checks for syntax mistakes before saving, which prevents a broken configuration. A single typo in the sudoers file can stop sudo from working for everyone, and that can leave you with no easy way to fix it.

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. You need to run it with sudo, because only administrators can edit the file.

🐧Bash / Shell
sudo visudo

This command launches the sudoers configuration inside the default editor. On most Ubuntu installs that is nano. Save and exit as you normally would in that editor. If visudo finds an error when you save, it tells you and asks what to do. Choose the option to go back and edit the file again rather than saving the broken version.

If you prefer the nano text editor, run this command instead to use it for that one session:

Advertisement

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. Open the file with visudo, as described above, and never with a plain text editor. This setup lets the user run administrative commands immediately without typing a password every time. It also reduces your system security, because anyone who gets at that session or account gets full administrator access with no further check.

⚠️WarningPasswordless configurations decrease system security.

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

Advertisement
💻Code
username ALL=(ALL:ALL) NOPASSWD: /bin/mkdir, /bin/rmdir

If you want to keep the convenience but still demand a password for the riskiest tools, you can add rules that enforce passwords for targeted utilities like apt and systemctl. The example below shows the rules you need:

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.

Editing the main sudoers file is not the only way to do this. A cleaner option is to give each user a dedicated file, so your changes stay separate from the stock configuration and are easy to remove later. To create a dedicated user file, run:

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

Add your custom rules to the new file. The syntax must match this example:

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

Tip: File names must not contain dots (.) or end in a tilde (~). Sudo silently skips files with names like that, so your rules will have no effect and you will get no error message. To undo a rule, delete or rename its file.

See What sudo Permissions a User Has

After any change, check what a user is actually allowed to do. To audit permitted commands for a specific user, run this command:

🐧Bash / Shell
sudo -l -U username

The output lists the commands the audited account may run with sudo, and any restrictions that apply. If the list is shorter or longer than you expected, review the rules you added and check the file name for a stray dot or tilde.

Summary

  • Easy method: Add users to the sudo group to give full sudo access. The user must log out and back in before it takes effect.
  • Control access: Edit the sudoers file or add files in /etc/sudoers.d for custom permissions, such as limiting a user to certain commands.
  • Always use visudo: It checks syntax before saving and prevents mistakes that could lock you out.
  • Be careful with passwordless sudo: It can make your system less safe, so use it only where you really need it.
  • Check sudo permissions regularly: Use sudo -l -U username to verify what each user can run.

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.

Advertisement

Frequently asked questions

How can I add a user to sudoers without a password in Ubuntu?

Add a NOPASSWD rule for the user in a sudoers drop-in file, but only for accounts you fully trust, since anyone who gets into that account gets full control without a password check. Run sudo visudo -f /etc/sudoers.d/username and add the line username ALL=(ALL) NOPASSWD: ALL, then save and exit.

How do I add an admin user on Ubuntu?

To add an admin user on Ubuntu, create the account with sudo adduser username, then run sudo usermod -aG sudo username. Admin here means membership in the sudo group, which lets the account run administrator commands after entering its own password. Log out and back in for the change to take effect.

How to add user in Ubuntu command?

Use sudo adduser username in the terminal to add a user in Ubuntu. The command asks you to set a password and fills in the full name and other details. Press Enter to skip any field you do not need. Replace username with the name you want for the account, using lowercase letters and no spaces.

How to make a user a superuser in Ubuntu?

To make a user a superuser in Ubuntu, add them to the sudo group with sudo usermod -aG sudo username. Members of this group can run commands as root by typing sudo before them. Ubuntu does not give a regular login a root shell by default, so this is the usual route. Log out and back in to apply it.

Still have a question?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

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

Leave a Comment

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