How to give a Linux user sudo access? [closed]
You need run visudo
and in the editor that it opens write:
igor ALL=(ALL) ALL
That line grants all permissions to user igor
.
If you want permit to run only some commands, you need to list them in the line:
igor ALL=(ALL) /bin/kill, /bin/ps
This answer will do what you need, although usually you don't add specific usernames to sudoers
. Instead, you have a group of sudoers and just add your user to that group when needed. This way you don't need to use visudo
more than once when giving sudo
permission to users.
If you're on Ubuntu, the group is most probably already set up and 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
On other distributions, like Arch and some others, it's usually called wheel
and you may need to set it up: Arch Wiki
To give users in the wheel group full root privileges when they precede a command with "sudo", uncomment the following line: %wheel ALL=(ALL) ALL
Also note that on most systems visudo
will read the EDITOR
environment variable or default to using vi
. So you can try to do EDITOR=vim visudo
to use vim
as the editor.
To add a user to the group you should run (as root):
# usermod -a -G groupname username
where groupname
is your group (say, admin
or wheel
) and username
is the username (say, john
).