How to Automatically Create Home Directory for Active Directory User on Solaris (using PowerBroker)

active-directoryhome-directorylikewise-opensolarisuser-accounts

I have a number of existing users in Active Directory that need a home directory created. They don't log directly in to Solaris but into a service running on that box.

If I login as them their home directory gets created and then they can login.

This is the same for new users too!

As there are a lot of users, I need a way to automate this so new users and existing users have it created automatically.

Is this possible??

Best Answer

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.