0

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
Buttle Butkus
  • 1,719
  • 8
  • 32
  • 45

2 Answers2

2

You will need to add the line

CREATE_HOME yes

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.

user9517
  • 114,104
  • 20
  • 206
  • 289
  • 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
0

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.

Edit

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

Flash
  • 1,290
  • 7
  • 10