CentOS 7 - Adding Users to Sudo

Most articles that talk about granting users sudo privileges do so by directly adding the user to the sudoers file. However, I am used to (and prefer) the Ubuntu way in which giving a user sudo privileges is as easy as:

sudo adduser [user] sudo  

To set this up in CentOS we need to create the sudo group (the commands below assume you are root).

groupadd sudo

Now we need to grant everyone in the sudo group the privileges by editing the sudoers file.


Add the following line to the appropriate area:

%sudo   ALL=(ALL)       ALL

Your file should now contain the following content.

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL  
%sudo   ALL=(ALL)       ALL

Now giving users sudo privilieges is as easy as:

sudo usermod -a -G sudo [user name]

Unfortunately I can't get useradd to work for me as it does on Ubuntu. I guess that's a post for another day, but I would be grateful if somebody posted the solution in the comments.



Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.