How can I add a regular user to the sudoers file?

35

11

How can I add more users to the "sudoers" file?

D'Arvit

Posted 2009-09-11T08:30:37.550

Reputation: 717

Answers

36

Just edit the file /etc/sudoers.

But you are supped to use /usr/sbin/visudo as your editor, since that will to some sanity checks before you exit.

So that would be:

sudo /usr/sbin/visudo

Here are some links that could be useful:

Johan

Posted 2009-09-11T08:30:37.550

Reputation: 4 827

Then how do I save the file – D'Arvit – 2009-09-11T08:55:42.290

1Never mind, realized it happened on the exit. – D'Arvit – 2009-09-11T08:59:12.640

1If you have an /etc/sudoers.d directory, don't modify the /etc/sudoers file. Instead, put the entry in its own file in that directory. – David Schwartz – 2013-02-06T06:48:57.113

+1. On some systems, the /etc/sudoers is readonly, and editiion is forced through the visudo command. – Laurent Etiemble – 2009-12-16T08:53:21.290

18

My preferred method is to add them to the sudo group (admin before Ubuntu 10.04).

In Ubuntu Linux, the sudo group can run sudo and it is easy to add someone to that group:

usermod -a -G sudo username

Your mileage may vary with other distros, however, someone thought the group method made more sense than the sudoers file getting itself updatified. Less room for getting it wrong and locking everyone out of being superuser seems to be the reason.

ʍǝɥʇɐɯ

Posted 2009-09-11T08:30:37.550

Reputation: 670

1admin group doesn't exist since at least Ubuntu 10.04 – Artem Pakk – 2011-06-29T11:01:42.407

13

Just edit your sudoers file

sudo visudo -f /etc/sudoers

and add the username like 'uk' without quotes

username ALL = (ALL)ALL

Save and exit would give the access.

ukanth

Posted 2009-09-11T08:30:37.550

Reputation: 9 930

6

Like Johan says, visudo should be used to edit the sudoers file. A borked sudo file can lead to a world of avoidable pain. http://en.wikipedia.org/wiki/Visudo

– None – 2009-09-11T09:04:11.943

3Why did you add quotes to your example, then? – user1686 – 2009-09-11T10:15:18.103

2

visudo opens the sudoers file and has samples for simple situations.

You may have to add option 'NOPASSWD' if user scripts would use commands/binaries which can be run only with "sudo", e.g.

ALL=(ALL) NOPASSWD: ALL

It is also possible to specify group instead of user name. So you need not list each and every user, e.g.

%users  localhost=/sbin/shutdown -h now

secureBadshah

Posted 2009-09-11T08:30:37.550

Reputation: 1 411

1Beware that NOPASSWD may be a security risk. – Johan – 2009-11-04T05:41:19.857

0

In Amazon Linux, there is /etc/sudoers.d and inside it is cloud-init which contains:

ec2-user ALL = NOPASSWD: ALL

# User rules for ec2-user
ec2-user ALL=(ALL) NOPASSWD:ALL

So all I did was cp cloud-init vlad, then edit vlad and replace all instances of ec2-user with vlad. Works fine, and it's obviously as it was intended to be done, rather than editing existing files.

Vladimir Kornea

Posted 2009-09-11T08:30:37.550

Reputation: 154

0

just by execute this command by a user which has a sudoer permission :

sudo adduser <username> sudo

Hadi Rahjoo

Posted 2009-09-11T08:30:37.550

Reputation: 1

0

Add to sudo group (Debian / Ubuntu specific step):

    $ sudo gpasswd -a <username> sudo

    Adding user <username> to group sudo

Shashi

Posted 2009-09-11T08:30:37.550

Reputation: 103