Here are some different ways to grant “sudo” permission to a user in Linux (tested on Ubuntu, but some methods here are universal in major Linux distributions).
Assuming that we want to make a user ‘hduser’ a “sudoer” :
$ sudo addgroup hdgroup $ sudo adduser hduser --ingroup hdgroup
.
1. Grant direct permissions to user via sudoers file
$ su root -c "vi /etc/sudoers"
Add a similar line to the line of ‘root’ :
## Allow root to run any commands anywhere
root ALL=(ALL) ALLhduser ALL=(ALL) ALL
.
2. Grant direct permission to user’s group via sudoers file
Instead of granting the permission to user, we will grant permission for a group to which the user belongs.
$ su root -c "vi /etc/sudoers"
Add a line for user group (hdgroup here), which starts with a “%” :
## Allow root to run any commands anywhere
%hdgroup ALL=(ALL) ALL
.
3. Add user to group ‘admin’ by command
(In RedHat-like system: CentOS, SUSE, etc… , the sudo group name is ‘wheel’ , not ‘admin’)
$ su root -c "vi /etc/sudoers"
Instead of granting the permission to user, we will grant permission for an existing group (such as wheel or admin), then add our user to that group.
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
$ useradd -G wheel hduser ## usermod -a -G wheel hduser
.
4. Add user to group ‘sudo’ by command
$ sudo usermod -aG sudo ducquoc
.
5. Add user to group ‘admin’ right when creating user
(In RedHat-like system: CentOS, SUSE, etc… , the sudo group name is ‘wheel’ , not ‘admin’)
$ sudo adduser ducquoc admin
.
6. Add user to group ‘sudo’ right when creating user
$ sudo adduser ducquoc sudo
.
7. Grant direct permission to user’s group via sudoers.d folder
.
gl & hf,
./.
Pingback: Synchronize time in Linux | DucQuoc's Blog
Pingback: Linux Basic Commands | DucQuoc's Blog