Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Add User to Sudoers in CentOS

How to Add User to Sudoers in CentOS.

To grant a user sudo access, you have two options. The first option is to add the user to the sudoers file, which contains information about which users and groups have sudo privileges and at what level. The second option is to add the user to the sudo group, which is defined in the sudoers file. By default, on RedHat-based distributions like CentOS and Fedora, members of the “wheel” group have sudo privileges.

To add a user to the “wheel” group, the easiest way is to run the following Command as root or another sudo user, replacing “username” with the actual username:

usermod -aG wheel username

Granting sudo access using this method is sufficient for most use cases. To test the sudo access, run the “whoami” command. If the user has sudo access, the command will print “root”. If you get an error saying “user is not in the sudoers file”, it means that the user doesn’t have sudo privileges.

sudo whoami

If you want to grant customized access to commands and configure custom security policies for the user, you can add the user to the sudoers file or create a new configuration file in the /etc/sudoers.d directory. To edit the sudoers file, use the “visudo” command. This command checks the file for syntax errors when you save it. If you open the file with a text editor, a syntax error may result in losing the sudo access. To allow a user to run sudo commands without being asked for a password, add the following line to the end of the file:

username ALL=(ALL) NOPASSWD:ALL

To allow the user to run only specific commands via sudo, add the following line:

username ALL=(ALL) /usr/bin/du, /usr/bin/ping

Alternatively, you can achieve the same by creating a new file with the authorization rules in the /etc/sudoers.d directory. This approach makes the management of the sudo privileges more maintainable. The name of the file is not important, but it is a common practice to name the file after the username.

echo "username  ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/username


This post first appeared on Microsoft, IT, System Center, Infrastructure, please read the originial post: here

Share the post

How to Add User to Sudoers in CentOS

×

Subscribe to Microsoft, It, System Center, Infrastructure

Get updates delivered right to your inbox!

Thank you for your subscription

×