Create home directories at login

In some situations it is important that home directories are created at login if they don't exist. Such scenarios include NIS or AD authentication, or when a local user is created without the -m option.

Fortunately PAM (Pluggable Authentication Modules) comes with a handy module to achieve this: pam_mkhomedir.

To use this one must add this line in a few of the pam config files, depending on the needs.

session    required  skel=/etc/skel/ umask=0022

The new home directory will be populated with all files and folders in /etc/skel.
The SKEL default location can be changed in /etc/default/useradd.

To create directories using local Login (as for instance in the console or graphical desktop), modify this file:



auth       required
auth       requisite
auth       include      system-local-login
account    include      system-local-login
session    required  skel=/etc/skel/ umask=0022
session    include      system-local-login

To create home directories when using ssh to login modify this file:


#auth     required     #disable remote root
auth      include   system-remote-login
account   include   system-remote-login
password  include   system-remote-login
session required skel=/etc/skel/ umask=0022
session   include   system-remote-login

To create directories when using 'su' to switch users, modify:


auth            sufficient
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth           required use_uid
auth            required
account         required
session    required  skel=/etc/skel/ umask=0022
session         required

An example:

login as: nisuser
nisuser@'s password:
Creating directory '/home/nisuser'.
Last login: Wed Dec  2 09:15:19 2015 from
[nisuser@archlinux2 ~]$

NOTE: It is important to add the module as the first session line. If you'd have this, for example:

session         required
session    required  skel=/etc/skel/ umask=0022

Then the module pam_mkhomedir would not be called.