pam_exec.so Execute Commands on User Login

In addition to the normal pam_mkhomedir.so I wanted to create a directory for each user on an alternative disk. To do so I edited:

vi /etc/pam.d/password-auth

added the line below (just above the line: session optional pam_mkhomedir.so)

session     optional      pam_exec.so /usr/local/bin/create_dir.sh

Then created the create_dir.sh file:

vi /usr/local/bin/create_dir.sh

and added the following:

#!/bin/bash
if [ ! -d /local/$PAM_USER ]; then
mkdir /local/$PAM_USER
chown $PAM_USER:ldapusers /local/$PAM_USER
fi
chmod +x /usr/local/bin/create_dir.sh

It is also possible to add extra options to pam_exec.so (man pam_exec) for debugging e.g.

session     optional      pam_exec.so debug log=/tmp/pam_exec.log /usr/local/bin/create_dir.sh

 

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>