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

Daily Email Updates
You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


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
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
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
(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!
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?
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.
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?
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.
found it – sudo userdel
thanks again for the helpful bit. very cool
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.
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.
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…
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!
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
@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
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.
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.
Tahnx for this help. I hate all the passwords
Excellent, thanks.
Michael Geary, you shouldn’t blame the tutorial because you didn’t read it properly.
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?
@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
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.