Adding a user to the sudoers file or group is an essential step for granting administrative (root) privileges on a Linux system. In this guide, we’ll walk you through how to safely give a user sudo access using the visudo
command, the recommended way to manage sudo permissions. Whether you're using Ubuntu, Debian, Fedora, Arch, or another distribution, we’ve got you covered with instructions tailored for each one.
Add User to Sudoers List: Grant Them Root Access
On Debian and Ubuntu based Linux systems, you can use the visudo
command to manage user privileges. Users in the sudo group are granted access to execute commands and files as root or administrator. This guide explains the straightforward process for adding a root user to Ubuntu, Debian, and other popular Linux distributions.

Important Note: Some Live distributions of Ubuntu and Debian do not have a root password set by default. If you're using a Live version, you must set a root password first before proceeding. See how to set a Debian or Ubuntu default root password.
How to Set a Root Password for Linux
To set a root password for Linux, assuming sudo is installed:
- Open a terminal: Ctrl + Alt + T
- Type the following command and press Enter:
sudo passwd root
Once you’ve set the root password, all the instructions in the following sections assume that the root account is enabled and has a password.
Add User to Sudoers on Ubuntu and Debian
- Open a terminal: Ctrl + Alt + T
- Switch to the superuser account:
sudo su
- Add the user to the
sudo
group. Replaceusername
with the actual username:usermod -aG sudo username
How to Fix bash: sudo: command not found
If you get an error like "bash: sudo: command not found", you can resolve this by typing:
apt -y install sudo
After completing this, test the new user's sudo privileges:
su - username
sudo apt update
Editing the Sudoers File with visudo
- Open a terminal: Ctrl + Alt + T
- Run the following:
sudo visudo
- Scroll to the bottom of the file using the arrow keys.
- Add the following line (replacing
username
with the actual username):username ALL=(ALL) ALL
- Press Ctrl + X, then Y, and Enter to save and exit.
Tip: To make editing easier, setnano
as the default editor before runningvisudo
:export EDITOR=nano
Granting Sudo Access on Other Linux Distros
The process of granting sudo privileges varies slightly between distributions. Below are methods for Arch Linux, Fedora, openSUSE, and Gentoo.
CentOS Add User to Sudoers (Wheel Group)
In CentOS, adding a user to the wheel
group grants sudo privileges. Here’s how to do it:
- Open a terminal.
- Switch to the root user:
su -
- Add the user to the
wheel
group:usermod -aG wheel username
- To test if the user was added successfully:
su - username
sudo whoami
Add User to Sudoers Arch Linux
- Install sudo (if not already installed):
pacman -S sudo
- Edit the sudoers file:
EDITOR=nano visudo
- Add the user to the sudoers list:
username ALL=(ALL) ALL
- Alternatively, add the user to the
wheel
group and enable it in sudoers:
Edit the sudoers file:EDITOR=nano visudo
- Uncomment this line:
%wheel ALL=(ALL) ALL
- Add the user to the
wheel
group:usermod -aG wheel username
Add User to Sudoers Fedora
- Add the user to the
wheel
group:usermod -aG wheel username
- Edit the sudoers file (if necessary):
sudo visudo
- Ensure the following line is uncommented:
%wheel ALL=(ALL) ALL
- Test sudo privileges:
su - username
sudo whoami
Add User to Sudoers openSUSE
- Install sudo (if not already installed):
zypper install sudo
- Add the user to the
wheel
group:usermod -aG wheel username
- Edit the sudoers file (if necessary):
sudo visudo
- Ensure the following line is uncommented:
%wheel ALL=(ALL) ALL
- Test the setup:
su - username
sudo whoami
Add User to Sudoers Gentoo
- Install sudo:
emerge --ask app-admin/sudo
- Add the user to the
wheel
group:usermod -aG wheel username
- Test sudo privileges:
su - username
sudo whoami
Frequently Asked Questions (FAQ)
- What is the sudoers file?
- The sudoers file is a system file in Linux and Unix-based systems that defines which users have access to use the
sudo
command to execute administrative tasks as the root user or another user with higher privileges. - How do I add a user to the sudoers file?
- To add a user to the sudoers file, you can either add them to the sudo group using the
usermod -aG sudo username
command or directly edit the sudoers file withvisudo
and add a line:username ALL=(ALL) ALL
. - What is the wheel group?
- The wheel group is a special group in Unix-based systems like CentOS and Fedora. Users in this group are granted the ability to execute commands as root using
sudo
. - How do I add a user to the wheel group?
- To add a user to the wheel group, you can use the following command:
usermod -aG wheel username
Afterward, ensure that the sudoers file has the line
%wheel ALL=(ALL) ALL
uncommented to allow wheel group members to usesudo
. - How do I check if a user has sudo privileges?
- You can check if a user has sudo privileges by switching to that user using
su - username
and then running a command likesudo whoami
. If the user has sudo access, the command will returnroot
. - Why should I use visudo to edit the sudoers file?
- You should use
visudo
to edit the sudoers file because it performs syntax checking before saving, reducing the risk of errors that could lock you out of sudo access. Editing the file manually can lead to syntax errors that can prevent sudo from working. - What do I do if I get a "bash: sudo: command not found" error?
- If you receive the error "bash: sudo: command not found", it means that the
sudo
package is not installed. To install it, run the following command as root:apt -y install sudo
- Can I remove a user from the sudoers list?
- Yes, you can remove a user from the sudoers list by deleting them from the sudo group or by removing the corresponding line from the sudoers file using
visudo
.
Additional Tips
Granting sudo privileges allows users to execute administrative commands, making it a powerful but potentially risky action. Below are some best practices to follow when managing sudo access to ensure security and proper system management:
- Use visudo to Edit the Sudoers File: The
visudo
command provides syntax checking and prevents misconfigurations that could lock you out of admin access. Avoid manually editing/etc/sudoers
- Use Groups Instead of Adding Users Directly: Instead of adding individual users to the sudoers file, it’s best practice to add them to the
sudo
orwheel
group. This simplifies user management and reduces the risk of accidental errors. - Grant Sudo Privileges Only to Trusted Users: Giving a user sudo access allows them to execute administrative commands, including potentially dangerous ones. Only provide sudo access to users who absolutely need it.
- Use NOPASSWD with Caution: While it’s possible to configure
sudo
so that users don’t need to enter a password, this reduces security. Use theNOPASSWD
directive only for trusted scripts or commands.
Conclusion
With these steps, you can grant users root access in Linux using the sudoers file for precise control. Always ensure you are careful while editing sudo permissions, as giving incorrect access can lead to security risks. If you follow these instructions, you’ll be able to manage user permissions and grant sudo access safely on a variety of Linux distributions.