Add user to sudo – CentOS 7

Enabling users to sudo in CentOS 7.  This post assumes you need to create a new user for the task AND that the wheel group is enabled in the /etc/sudoers file.

Somehow, you’ll end up a the CLi, be that an SSH client, via Terminal at the GUI directly on the box, using your mobile device or whatever floats your particular boat. Remember to replace USERNAME with the actual username you want to use.

First up, add the user

useradd USERNAME

And then set the password.


You’ll need to set the password and confirm it here, look out for any warnings or errors…

Now we can add the user to the wheel group

usermod -aG wheel USERNAME

And that that.  Open a new session, login as the new user and try someting like

cat /etc/sudoers

and you should see.

cat: /etc/sudoers: Permission denied

Change the command to be

sudo cat /etc/sudoers

You should then be prompted for your sudo password (login password) and be granted access to view the file, or run any other root command you require.

You may find that the wheel group is ot enabled in the sudoers file.  if so, as a root user open the file for editing (I prefer nano, use whatever you like)

nano /etc/sudoers

and find the following line.

#%wheel ALL=(ALL) ALL

remove the preceding # so the line reads.

%wheel ALL=(ALL) ALL

Use CTRL+O to save the file and CTRL+X to exit the editor (in nano), then try to sudo as the new user in a new session.

Leave a Reply

Your email address will not be published. Required fields are marked *