Unlike Linux, there is no standard pam module like pam_mkhomedir to achieve this task on Solaris. While compiling this pam module would likely just work, there are alternatives like creating the home directory if missing in /etc/profile or setting up an executable auto_home map.
Using /etc/profile to create the user's home directory would require using rbac or sudo so an automounter based solution is simpler to implement, eg:
In the /etc/auto_master
file, comment out the line:
# /home auto_home -nobrowse
and add this line:
/home /opt/local/mkhomedir
Note: I'm assuming here the previous auto_home map wasn't already used by actual users.
Create the /opt/local/mkhomedir
script with this content:
#!/bin/ksh -p
actual=/tmp/home # top directory to store user's home directories
homedir=$(echo ~$1)
hd=$actual/$1
if [ $(dirname $homedir) = /home -a ! -d $hd ]; then
mkdir -p $hd
chmod 0700 $hd
chown $1 $hd
fi
echo localhost:$hd
and that's it. Every user configured to have his home in /home/username will have this directory automatically created at first access if necessary. Of course, you should replace /tmp/home
by something more persistent in the mkhomedir
script, eg /export/home
which is the usual location for home directory back-end storage on Solaris.