How to Add a User to Sudoers in Ubuntu
| Task | Command |
|---|---|
| Add user to sudo group | sudo usermod -aG sudo username |
| Check user groups | groups username |
| See user’s sudo permissions | sudo -l -U username |
| Edit sudoers file safely | sudo visudo |
| Create sudoers file for user | sudo visudo -f /etc/sudoers.d/username |
| Test sudo access | sudo 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.
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:
sudo usermod -aG sudo usernameStep 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:
su - usernameCheck the User’s Groups
To confirm membership within the sudo group, execute this command:
groups usernameThe target user's name appears in the resulting output.
Test sudo Access
Switch to the target account and execute:
sudo whoamiA password prompt followed by root output confirms operational sudo 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.
visudo for file edits. This utility checks syntax mistakes prior to saving, preventing broken configurations.Open sudoers File Safely
In the terminal, run:
sudo visudoThis 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.
username ALL=(ALL:ALL) NOPASSWD: /bin/mkdir, /bin/rmdirAlternatively, 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:
sudo visudo -f /etc/sudoers.d/usernameAppending custom rules requires syntax matching this example:
username ALL=(ALL:ALL) NOPASSWD:ALLTip: 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 usernameOutput displays permitted and restricted commands for the audited account.
Summary
- Easy method: Add users to the
sudogroup to give full sudo access. - Control access: Edit the sudoers file or add files in
/etc/sudoers.dfor 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 usernameto 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?
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.
No comments yet — be the first to share your thoughts!