How to grant access to user sudo for Linux?

I am trying to give sudo access to one of my users. What should I enter into the terminal?

+48
linux sudo
Jun 19 '12 at 5:23
source share
3 answers

You need to run visudo , and in the editor open it:

 igor ALL=(ALL) ALL 

This line grants all permissions to the igor user.

If you want to allow execution of only certain commands, you need to specify them in the line:

 igor ALL=(ALL) /bin/kill, /bin/ps 
+63
Jun 19 '12 at 5:25
source share
— -

This answer will do what you need, although usually you do not add specific usernames to sudoers . Instead, you have a sudoers group and just add your user to this group when necessary. Thus, you do not need to use visudo more than once when granting users sudo permission.

If you are on Ubuntu, the group is most likely already configured and is called admin :

 $ sudo cat /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # 

...

 # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d 

In other distributions, such as Arch and some others, it is usually called wheel , and you may need to configure it: Arch Wiki

To give full privileges to users of the wheelset group when they precede the command with "sudo", uncomment the following line:% wheel ALL = (ALL) ALL

Also note that on most systems, visudo will read the EDITOR environment EDITOR or use vi by default. Therefore, you can try EDITOR=vim visudo use vim as an editor.

To add a user to a group, you must run (with root privileges):

 # usermod -a -G groupname username 

where groupname is your group (say admin or wheel ), and username is the username (say john ).

+55
Jun 19 2018-12-12T00:
source share

Modify the /etc/sudoers file manually or using the visudo application. Remember: the system reads the /etc/sudoers file from top to bottom, so you can overwrite a specific parameter by setting the following below. Therefore, to be safe, define the access setting below.

-5
Jun 19 2018-12-12T00:
source share



All Articles