How To Add User To Sudoers Centos

How To Articles

Adding a user to the sudoers file in CentOS is an essential task for system administrators. The sudoers file determines the privileges and access levels of each user on the system. In this article, I will guide you through the process of adding a user to the sudoers file in CentOS, step by step.

Step 1: Log in as root

Before we begin, make sure you are logged in as the root user or a user with sudo privileges. This is necessary as only privileged users can edit the sudoers file.

Step 2: Open the sudoers file

Now, let’s open the sudoers file using a text editor. In CentOS, the sudoers file is located at /etc/sudoers. However, it is recommended to use the visudo command instead of directly editing the file. This command opens the sudoers file in a safe mode and performs syntax checking to prevent any mistakes.

$ sudo visudo

This command will open the sudoers file in the default text editor, usually vi or nano.

Step 3: Add the user to the sudoers file

Once the sudoers file is open, scroll down to the section that defines user privileges. You will see lines starting with the keyword User privilege specification. Below this section, add a new line to specify the user and their privileges.

User privilege specification
root    ALL=(ALL) ALL
your_username    ALL=(ALL) ALL

Replace your_username with the actual username of the user you want to add to the sudoers file. The syntax your_username ALL=(ALL) ALL grants the user full administrative privileges.

Step 4: Save and exit

After adding the user to the sudoers file, save the changes and exit the text editor. In vi, you can do this by pressing Esc followed by typing :wq and hitting Enter. If you are using nano, press Ctrl+X to exit and Y to save the changes.


Adding a user to the sudoers file in CentOS is a straightforward process that requires root or sudo privileges. By following the steps outlined in this article, you can grant administrative privileges to specific users and ensure the security and management of your CentOS system.