This is exactly what
pam_mkhomedir was made for.
pam_mkhomedir module can create the user's home directory upon login if that directory does not exist.
How to install it depends upon your distribution. But you would need to put it in one or more files in
For example, on my system I have
/etc/pam.d/system-login which is included by all other services which perform login (ssh, gdm, etc).
I would put
pam_mkhomedir.so in the
session stack, such as:
session optional pam_loginuid.so
session required pam_env.so
session optional pam_lastlog.so
session include system-auth
session optional pam_mkhomedir.so # <<< right here
session optional pam_ck_connector.so nox11
session optional pam_gnome_keyring.so auto_start
session optional pam_motd.so motd=/etc/motd
Where you put it is entirely dependent upon what else is in the stack. But you should put it before anything else which might need the home directory.
man 8 pam_mkhomedir for the options it supports.