How to create a user with root privileges in bash?
Solution 1
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
.
Solution 2
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
Solution 3
"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.
Related videos on Youtube
Nathan Osman
Email: [email protected] I am both an Ubuntu user and Ubuntu member. By profession, I am a software developer and I work with C++, Python, and (more recently) Go. I enjoy tinkering with different things like motion tracking in Blender, creating an Android app for time-lapse photography, or writing Linux kernel modules. - 2buntu - community blog that I sometimes contribute to - NitroShare - a cross-platform network file transfer utility - REST Easy - Firefox add-on for analyzing HTTP responses
Updated on September 18, 2022Comments
-
Nathan Osman over 1 year
I have run the following commands:
sudo groupadd -r testgroup sudo useradd -g testgroup -M -r testuser
Notice the
-r
option, which according to theman
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?
-
Nathan Osman about 13 yearsAh... no wonder it wasn't working.
-
papukaija over 11 yearsFor 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.
-
Yuriy Nakonechnyy almost 10 yearsOn Ubuntu 14.04 I get
adduser: Specify only one name in this mode.
when executingsudo adduser --group sudo ubuntu
-
BuZZ-dEE about 9 yearsAlso on Ubuntu 12.04.5 LTS it does not work.
-
H2ONaCl about 7 yearsAs @Yura said, in response to the command
adduser --group sudo username
is the messageadduser: Specify only one name in this mode.
This is probably a failure because subsequently it is possible to add that same user via the commandadduser 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
.