• ARTICLES
SEARCH

How-To Geek

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.

Note: if you get a message saying that the command is not found, try using the full path, like this:

/usr/sbin/useradd <username>

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

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 12/15/06

Comments (36)

  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?

  8. OMo

    dammit, I wish I’d read Michael Geary’s post from March 10, 2008 3:23 pm before I did a useradd.

    anyway, thanks for the last 3rd of the post – very helpful. perhaps you could add a bit on the end for people like me that want to delete the user that we just useradded.

  9. OMo

    found it – sudo userdel

    thanks again for the helpful bit. very cool

  10. anon

    I wanted to add a user whose home directory would be outside the /home tree, so useradd was exactly what I wanted. The first 2/3rds may not be useful for some readers, but for others really good. Thanks.

  11. mehul

    I have kubuntu 7.10,
    i have faced so many problems with kubuntu login,
    3 times it happend that when i give right pass for any user x windos system doesnt get start and again login dilog opens and there is no loginfail message,
    when i gives wrong password it gives message of login fail ….

    when ever this happens i have no any othere choice then reinstall kubuntu.

    And now this time i have new problem that if even i give right password it doesnt do any thing, i tried one more thing in this case, i gone to generic recovery mode and created new user mehul and set its password , and then tried to , this time it started x windows but given the message kaconfig application loading fail ! please check the installation.

    now i dont know y this is happning to me with kubuntu?

    all other linux flavours are ok with me but only kubuntu is having this problem to me.

    I have laptop : compaq pressario c 300
    on which i installed kubuntu.

    Please help me if any one knows solution to this.

  12. Neil Twist

    That sounds like an X problem rather than a user problem.

    try pressing +2, Do you get a login prompt? if not try ++2, or try F2 instead of 2.

    Anyway, you should get a command line login prompt. Try logging in here, if this works, then it’s an X problem (or something else, but not a user problem) and you can get to the log files to debug it…

  13. Gaz

    Michael Greary you are a D&%K H#$&D. You’re the 1 that messed it up no1 else, and anyone else for that matter.

    Hopefully you’ve learnt by now that when blindly running linux commands you should read the whole article to make sure it’s what you want first.

    Blaming it on other ppl isn’t gonna help either. You should’ve said it by admitting your mistake, asking for a way to rectify it.

    (sigh) I bet you have no friends

    Nice how to by the way. Helped me with something I was stuck on, so thanks!

  14. Basil Kurutz

    I am trying to install ubuntu 8.1 and get it to work with a Windows XP computer. Installed, I get to boot both ubuntu and XP, but booting ubuntu my name and passwrod don’t match and I can’t get much further. I only use my computer to write and am not a geek to go much further. ADVISE! BASIL

  15. Redis

    @Mehul : You may have your hard drive full. Kde fails to login when it does not have enough space for tmpfiles and gets you back to login screen

  16. Erik

    Hey guys, anyone know if there is anyway to pass the password along with the useradd command, instead of having it prompt for a password twice.
    Trying to write a web admin page to add users amongst other things.

  17. Terje

    I really burnt myself by using useradd instead of adduser, I think you should put adduser at the top as it is the most “human” way of creating a user, especially for n00bs that often seeks this how-to guides.

  18. Chuck

    Tahnx for this help. I hate all the passwords

  19. Bouffant

    Excellent, thanks.

    Michael Geary, you shouldn’t blame the tutorial because you didn’t read it properly.

  20. Gralha

    Hi there,
    as a newbie to Linux (Ubuntu Server 9.04) I would like to know a simple thing… how do I add a user to a Group?

  21. beanfarmer

    @Erik mkpasswd will create an encrypted password for you, you will have to apt-get whois to install it though then just figure out a way of passing the input password from the user to mkpasswd and the output of mkpasswd back to useradd

  22. wideyes

    Wait, let me get this straight – people are complaining because they messed up?

    *Perhaps those with slippery fingers should not be dabbling with the command line.*

    Is this the root of the complaint? Or have others who correctly used the useradd command still had problems? What are the concrete symptoms (other than user error) that have arisen through use of this command? I’m genuinely curious, because it worked just fine on my system.

  23. MrThankyousomuuch

    thanks so mmuch

  24. ben thomas

    I am a complete newbie to ubuntu , when i tried to use the useradd command to create an account for routine work ,i encountered this error message –”cannot lock /etc/passwd ”
    this was on ubuntu 9.10
    on kubuntu the problem persisted in adifferent manner the system generating a mesage “only root may add users to the system ”
    what am i doing wrong, also ANY time I try to use ANY application all kinds of update windows open up once the gazillion different packages are downloded , nothing apparent happens , even after reboot , there is no prompt from the system about any installations and the circle restarts when i click on some other application.please help

  25. Doug

    @Ben This is probably not the best place for that kind of question. You might try ubuntuforums.org. Essentially though, if you put sudo in front of the command, it should work.

    @everyone I still don’t know how to pass the temporary password to useradd. I could do this in Fedora very easily because they have –stdin, but ubuntu doesn’t seem to have that. We make users change their password before they take the machine, so passing plain text is fine. In fact, I’m pretty sure that will be the only acceptable solution to my problem, so mkpasswd will not be involved in a solution. Thanks!

  26. Liberty

    Hi, I cannot manage to remember the syntax for useradd, and I always come to this site every time. However I found a tutorial that also has the command to set the default shell to bash also.
    useradd -d /home/kevin -s /bin/bash -m kevin
    If you need it again I found it here -> https://www.aplacetocode.com/tutorials/first-time-server-tutorial/

  27. adam

    You really should do all of your readers a favor and remove this page.

    This page is the first hit for the Google search ubuntu add user.

    In Ubuntu the recommended way of adding users is *not* “useradd”

    Get that? In Ubuntu the recommend way to add users is: “adduser”

    Do your readers a favor and delete this entire post!

    Thank you,
    Adam.

  28. adam

    This comment is just plain wrong:

    “You can alternatively set a password using -p”

    NO NO NO! Check it out:

    man useradd
    -p, –password PASSWORD

    The encrypted password, as returned by crypt(3). The default is to disable the password.

    Get that? Not the password but the encrypted password. The difference is that “-p” will put the string you type here directly into /etc/shadow

    Most likely *NOT* what the average user is expecting (DOH!).

  29. Andrew

    I agree with Anon… I wanted to create a user, however I didn’t want his home directory to be in /home/. What I wanted was a user with a home folder in a different location. Useradd is what I needed.

    I am still relatively new to Ubuntu, but like what I see so far. When I see something that doesn’t seem to make sense, I find that in time, clarity will come. There’s a reason for everything here.

  30. Bouncy Castle Hire Weston-Super-Mare

    THANK YOU
    for this article !
    I am on DAY 1 of Ubuntu , I need to run a services server and a friend offered to help out, he has *some* nix experience, but wanted me to create him an admin account.

    Thanks to this article (and the adduser) command I added him perfectly fine, although I do now need to find out how to add accounts for non admins which cannot go into other directorys and only gives 50mb ‘storage’ .. but thats the next part of my research :)

    Thanks again

  31. JohnC

    Thanks for taking the time to create this how to article, and the other Linux content on your site!\.

    I’m using Ubuntu on VMWare to learn to manage a Linux server using only the command line, and your site has a lot of information that will help me.

    I found this post very helpful …as well as some of the comments. Thanks!

  32. Jack

    Put adduser at the top.

    Also, adduser is broken – it shouldn’t ask for this information, it is redundant, irrelevant and a broke implementation:

    Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
    Is the information correct? [Y/n]

    This is broken and wrong, the command should not ask for this information, it is a flawed design, it just annoys me that whoever wrote this wanted to make the command “more important” and just wastes six more keystrokes of everyone else’s life. Thanks.

  33. jozef

    Hi,
    For over 10 years I was using autoadd (batch adduser proggram) written in C to add students accounts on solaris and aix. As input was created file with records of ‘username password’. Now I’m moving one of servers running on ibm with aix to VMware with ubuntu and here I have problem with migration users (over 1000) and also later with adding new users because for some reason I’m not able to compile this program on ubuntu??
    Maybe someone know batch adduser program which will run on ubuntu.
    Any clue will be appreciated
    Thank you

  34. aakash

    Thanks buddy for this article. This help me a lot….

  35. ASVTX

    So useradd allows you to create user dirs outside of the home directory, and adduser allows you to enter some extra useless information… yet there are some people complaining that useradd is wrong.

    Im more than happy to be ‘wrong’ if I get more control, and if you look, its a hell of alot more control. If you prefer adduser, then you will most likely prefer windows.

    Oh, and Ubuntu has no problems at all with useradd, just Debian, so go to Debian article instead of complaining on a Ubuntu one??

  36. ArcticFox

    Um… for those of you complaining about having messed up your Ubuntu because you tried useradd before adduser and blaming the author of this article for your trouble…

    …Didn’t it occur to you to read the entire article BEFORE banging out root level commands into your system?

    …just sayin’

Enter Your Email Here to Get Access for Free:

Go check your email!