I don't remember modifying CentOS useradd to get this behavior.

useradd in CentOS creates the user's home directory with all the normal files (like .bashrc).

I modified /etc/default/useradd to make it looks like CentOS (just required some uncommenting) except for Ubuntu having SHELL=/bin/sh instead of SHELL=/bin/bash

How do I make useradd act like it does in CentOS? Is there some existing option to change? Or should I just add an alias to /etc/bash.bashrc?

The difference: On Ubuntu, useradd is not creating the home directory.

as root:

$ useradd test
$ cd ~test
-su: cd: /home/test: No such file or directory
  • 1
    Having made you /etc/default/useradd the same on both systems - what is not working as you expect ? – user9517 Nov 29 '12 at 10:05
  • Sorry, should have explained that! Editing now. – Buttle Butkus Nov 29 '12 at 10:09

You will need to add the line


to /etc/login.defs

From the Ubuntu useradd man page

-m, --create-home


By default, if this option is not specified and CREATE_HOME is not enabled, no home directories are created.

Although the CentOS man page is more helpful as it says

... useradd will create the home directory unless CREATE_HOME in /etc/login.defs is set to no.

| improve this answer | |
  • That's what I needed. Compared the login.defs on both systems and that was the difference. As soon as I changed it on the Ubuntu system, useradd started acting just like on CentOS. – Buttle Butkus Nov 29 '12 at 10:31

On creating the home directory, useradd actually copies the directory /etc/skel. There for if you want to have some settings already added to new home folders its as simple as adding the files to /etc/skel and the next time you add a user, those files will be in the home directory.


Use useradd -m username this works on both centos and ubuntu.

| improve this answer | |
  • It's not even creating home directories. – Buttle Butkus Nov 29 '12 at 10:08
  • You're right about the command line, but I wanted to change the defaults. lain's answer provides the correct location and environment variable. – Buttle Butkus Nov 29 '12 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.