Programster's Blog

Tutorials focusing on Linux, programming, and open-source

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.

Last updated: 9th January 2023
First published: 16th August 2018