Grant User sudo Privilege

Let’s see how to grant a regular user sudo privilege, this is summaried from process to use regular user instead of root. Use of sudo does not require access to the superuser’s password. If Authenticating, using sudo requires the user’s own password.

Say, there is a regular user named guest, the simplest way is to edit sudoers file solely, run as root user:

1
visudo

Append this line after root user field

1
2
3
# root    ALL=(ALL)       ALL
# 如果需要仅仅开放某些命令,这里可以进行调整
guest ALL=(ALL) ALL

Then user guest can run sudo free.

Another way is adding guest user to wheel group then give this special group password-less sudo privilege.

why uses wheel? Because sometimes I also need grant su password-less to the user, wheel group is easy for both. See my blog <<Linux PAM Module Configuration>>

Run as root user, add guest to wheel group:

1
usermod -a -G wheel guest

Then edit sudoers file

1
visudo

Comment and uncomment like this:

1
2
3
4
5
## Allows people in group wheel to run all commands
#%wheel ALL=(ALL) ALL

## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL
0%