Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

Add a User on Ubuntu Server

Ubuntu Server is like any Linux variety, and has full multi-user capabilities, and a common task on any server is adding users.

useradd

The useradd command will let you add a new user easily from the command line:

useradd <username>

This command adds the user, but without any extra options your user won't have a password or a home directory.

You can use the -d option to set the home directory for the user. The -m option will force useradd to create the home directory. We'll try creating a user account with those options, and then use the passwd command to set the password for the account. You can alternatively set a password using -p on the useradd command, but I prefer to set the password using passwd.

sudo useradd -d /home/testuser -m testuser

sudo passwd testuser

This will create the user named testuser and give them their own home directory in /home/testuser. The files in the new home directory are copied from the /etc/skel folder, which contains default home directory files. If you wanted to set default values for your users, you would do so by modifying or adding files in that directory. If we take a look at the new home directory for the user:

geek@ubuntuServ:/etc/skel$ ls -la /home/testuser
total 20
drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34 .
drwxr-xr-x 5 root root 4096 2006-12-15 11:37 ..
-rw-r–r– 1 testuser testuser 220 2006-12-15 11:34 .bash_logout
-rw-r–r– 1 testuser testuser 414 2006-12-15 11:34 .bash_profile
-rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc

You'll notice that there are bash scripts in this directory. If you wanted to set default path options for all new users, you would do so by modifying the files in /etc/skel, which would then be used to create these files by the useradd command.

adduser

The adduser command is even easier than the useradd command, because it prompts you for each piece of information. I find it slightly funny that there are two virtually identically named commands that do the same thing, but that's linux for you. Here's the syntax:

adduser <username>

Example:

geek@ubuntuServ:/etc/skel$ sudo adduser thegeek
Password:
Adding user `thegeek'…
Adding new group `thegeek' (1004).
Adding new user `thegeek' (1004) with group `thegeek'.
Creating home directory `/home/thegeek'.
Copying files from `/etc/skel'
Enter new UNIX password:
Retype new UNIX password:
No password supplied
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for thegeek
Enter the new value, or press ENTER for the default
Full Name []: The Geek
Room Number []: 0
Work Phone []: 555-1212
Home Phone []: 555-1212
Other []:
Is the information correct? [y/N] y

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 12/15/06 and tagged with: Ubuntu, SysAdmin

Comments (7)

  1. Taurai Mhokore

    I would like to create 3 users who will be having administrative rights like ones "root" user eg installation of applications etc.

    How would I do it. Please send me a full creation example. Users : Mercy123, Taurai123, Timothy123.

    I would also want to be able to check logs to see what each users has been doing, from which machine, when and what time, how will I check that on the system?

    Im running Ubuntu Linux 7.04

    Im desperately in need of your help.

    Taurai Mhokore
    +27 7981 96290

    Please help

  2. Travis

    Taurai,

    Are you talking about everything under the sun for user activity, or just email, or another service? You can find out most everything you need to know from the log files located in /var/log However, if that doesn't help you out, feel free to email me at tbeehler AT linuxmail DOT org and I'll gladly walk you through any help you may need.

    You can use a simple "grep" command to look for specific things, such as all emails sent through your system by a user such as

    grep -i "mercy123″ /var/log/mail.log

    The above command will show you everything related to user "mercy123″ including incoming and outgoing email. The -i is to make sure that your search is case insensitive. The above command is a very basic way to look at activity, so if you want something a little more robust, let us know and we'll be happy to help you out.

    Travis

  3. Daniel

    Does creating a new user on a ubuntu server automatically give them an email address as well.

    basically just out of curiosity if i was to add user jsmith to server running ubuntu 7.10 on domain underwear.com, would this also create jsmith@underwear.com?

    any help would be appreciated.

    Cheers
    Daniel

  4. Michael Geary

    (sigh) I just messed up adding a user on my Ubuntu server, thanks to this article. I followed the useradd example with the home directory, left out the -m by mistake, and now I don't know what the command actually did.

    So, I do a "man useradd" and what do I see: "useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead."

    Sure enough, the article does mention adduser - almost in passing at the end.

    Do your next reader a favor and simply take out all the useradd stuff. Is there anything in those examples that couldn't have been done with adduser? useradd is easy to get wrong like I did, and the man page itself says "don't use it." If you mention useradd at all, don't list any examples of its syntax, just put a little note at the end of the article saying that it's a low level command and not recommended for everyday use.

    Thanks!

  5. ano

    so there is no way to create a new user in a humane way? I'm not going to mess with my ubuntu installation, but at the same time I can't use it properly if I don't have a password-protected user for myself. is there a non-cryptic way of adding users?

  6. Michael Geary

    Yes, there is an easy way to add a user. Just skip the entire first 2/3 of this article that describes the cryptic and *NOT RECOMMENDED* useradd command, and go right to the end where it mentions the adduser command. That's the one you want. It's very easy to use.

  7. Neil Twist

    Hi Michael,

    Leaving off -m just doesn't create the directories involved. you will need to do something like:
    "sudo cp -r /etc/skel /home/[new_username]"
    then something like
    "sudo chown -r [new_username]:[new_username] /home/[new_username]"

    Do you have a group for the user?


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.