How to create a user with root privileges in bash?

63,081

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.

Share:
63,081

Related videos on Youtube

Nathan Osman
Author by

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, 2022

Comments

  • Nathan Osman
    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 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?

  • Nathan Osman
    Nathan Osman about 13 years
    Ah... no wonder it wasn't working.
  • papukaija
    papukaija over 11 years
    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.
  • Yuriy Nakonechnyy
    Yuriy Nakonechnyy almost 10 years
    On Ubuntu 14.04 I get adduser: Specify only one name in this mode. when executing sudo adduser --group sudo ubuntu
  • BuZZ-dEE
    BuZZ-dEE about 9 years
    Also on Ubuntu 12.04.5 LTS it does not work.
  • H2ONaCl
    H2ONaCl about 7 years
    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.