PAM-script: Execute Scripts at Authentication, Session Open and Close
Introduction
You may need to run some operations at authentication, session opening or closing. Here is a PAM module I’ve found that allows this functionality.
Installation
Download the module from the Freshmeat project and extract it:
|
|
Now install the dependencies:
|
|
Now compile it:
|
|
Now you just need to copy it:
|
|
Configuration
PAM
Session
If you want to launch something with root permissions at session startup, edit the /etc/pam.d/common-session
and add this line:
|
|
After pam_script, you can configure:
- runas: choose the user you want to run script (runas=root)
- onsessionopen: this script will be launched on started session (onsessionopen=/etc/security/onsessionopen)
- onsessionclose: this script will be launched on closed session (onsessionclose=/etc/security/onsessionclose)
Auth
You may also want to launch something at authentication:
|
|
Scripts
Just create the default scripts and add the necessary permissions:
|
|
And add this minimum content:
|
|
Test & Debug
You can now test by adding for example “touch /tmp/test_ok” on the “onsessionopen” script. To have more details, please look at the logs:
|
|
All looks good :-)
Last updated 14 Mar 2010, 19:40 +0200.