home directory is not created with adding user resource with chef

chef-infra, chef-recipe, linux

Solution

While system users usually don't have a home dir, chef will create the home dir even for system users if you specify `home`. I've tried it, and cannot reproduce the issue.

What is going on is a little bit hidden in the documentation. The chef documentations says:

system | Use to create a system user. This attribute may be used with useradd as the provider to create a system user which passes the -r flag to useradd.

If have a look at the man page of useradd:

-r, --system
     Create a system account.

   System users will be created with no aging information in /etc/shadow, 
   and their numeric identifiers are chosen in the SYS_UID_MIN-SYS_UID_MAX
   range, defined in >/etc/login.defs, instead of UID_MIN-UID_MAX 
   (and their GID counterparts for the creation of groups).

   Note that useradd will not create a home directory for such an user,
   regardless of the default setting in /etc/login.defs (CREATE_HOME). 
   You have to specify the -m options if you want a home directory for
   a system account to be created.

However, it seems like chef is passing the `-m` option explicitly if you specify a home dir. I could not reproduce this issue therefore.

Problem

On a vagrant box precise64 (ubuntu 12.04) While creating a user resource with Chef, the home directory is not created: My recipe: ``` user "myuser" do supports :manage_home => true shell "/bin/bash" home "/home/myuser" comment "Created by Chef" password "myencryptedpassword" system true provider Chef::Provider::User::Useradd action :create end ``` When I authenticate: ``` $ su - myuser Password: No directory, logging in with HOME=/ ``` Update - The workaround for precise64 (Ubuntu 12.04 64bit) ``` directory "/home/myuser" do owner "myuser" group "myuser" mode 00755 action :create end ```

Original source