171

I want to grant a newly created user sudo privileges in Ubuntu.

I tried

sudo adduser hduser admin

but it says no admin group exists. How can I do it?

jdthood
  • 12,467
saket
  • 1,821

4 Answers4

249

You need to add the user hduser to the sudo group (which is the "administrators" group in Ubuntu).

If you have already created the user, you can add the user to the sudo group by running the following command in a Terminal:

sudo usermod -a -G sudo hduser
vabada
  • 291
ish
  • 139,926
28

Instead you can try,

sudo adduser hduser sudo

In Ubuntu you need to add the user only to the group sudo.

Zanna
  • 70,465
Aishwarya
  • 381
16

1) Become root. You can do this using sudo -i or becoming root the old fashioned way su -

2) Run visudo

3) I changed this portion of the sudoers file to have my chosen users become sudo users, and you can add users similarly (blank lines introduce to format cleanly):

## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem dbadmin 
ALL=(ALL) ALL
ics ALL=(ALL) ALL 
csm ALL=(ALL) ALL 
coa ALL=(ALL) ALL

4) Press : and x to write the changes to sudoers and exit vi.

Braiam
  • 67,791
  • 32
  • 179
  • 269
  • 3
    This seems needlessly complicated. Why bother running visudo when the adduser command will do what you want? – Dan Dascalescu Jul 11 '14 at 09:29
  • 2
    @dan-dascalescu - $ sudo adduser username sudo won't work if the 'sudo' group does not exist. So adding the user manually is certainly an option. However, it's certainly more elegant to create a sudo group, add it to the sudoers file (e.g. via visudo), then add the appropriate user(s) to that user group. – Jarrett Barnett Oct 02 '15 at 17:47
  • 1
    @JarrettBarnett That was the case for me. Thank you for your answer. – Marcel Mar 21 '16 at 22:47
5

Edit the sudoers file: sudo visudo

and add:

user    ALL=(ALL:ALL) ALL
Zanna
  • 70,465