13

I have run the following commands:

sudo groupadd -r testgroup
sudo useradd -g testgroup -M -r testuser

Notice the -r option, which according to the man page:

-r
    Create a system account.

Assuming I have a user account with root privileges, I then run:

sudo -u testuser cat /dev/input/mouse0

However, I get:

cat: /dev/input/mouse0: Permission denied

Running the same command as root provides the expected output (garbled output from the mouse driver).

How can I create a user with root privileges?

1

5 Answers 5

22

Haven't tried it but this should create a new user and add them to the sudo group, which if your /etc/sudoers is as default, should mean they're allowed to use sudo with their password (just like the standard first user):

sudo adduser --group sudo newusername

If you've already created the user, you can just run:

sudo adduser existing_user sudo

man adduser will show you some of the other billion permutations and combinations of arguments this tool has.

Note: If you use Ubuntu 11.10 or older, you should use the admin group instead of sudo.

5
  • Ah... no wonder it wasn't working. Mar 31, 2011 at 0:11
  • For 12.04 (Precise) and newer: The default group for root privileges is sudo but admin will work too. However, new installs won't have the admin group created at all.
    – papukaija
    Dec 27, 2012 at 0:29
  • 4
    On Ubuntu 14.04 I get adduser: Specify only one name in this mode. when executing sudo adduser --group sudo ubuntu Jul 30, 2014 at 17:39
  • Also on Ubuntu 12.04.5 LTS it does not work.
    – BuZZ-dEE
    Mar 13, 2015 at 11:00
  • As @Yura said, in response to the command adduser --group sudo username is the message adduser: Specify only one name in this mode. This is probably a failure because subsequently it is possible to add that same user via the command adduser username. This was observed on 16.04. The way to add a new user as a sudoer might require 2 commands: adduser username && adduser username sudo.
    – H2ONaCl
    Feb 9, 2017 at 0:57
3

I found some sites where they do the: sudo adduser paul admin

but my linux does not have the admin group so I use:

sudo adduser paul sudo
2

"System account" just means that the user will get an UID (user identifier) from a reserved range, it doesn't give any extra permissions. The right way to elavate privileges is to use sudo, as described by Oli.

0

The following worked on Ubuntu 16.04 LTS:

sudo adduser robert && sudo adduser robert sudo

Creates the user and adds him/er to the sudoer list

0
sudo usermod -a newuser -G sudo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .