How to have pam_exec run the script as the current user?

view story

http://unix.stackexchange.com – I need to run a script, when the session is opened, as the user who's opening the session. I have added in /etc/pam.d/common-session : session optional pam_exec.so log=/tmp/test_pam_foo.log /usr/local/bin/test_pam_foo.sh I also tried to activate pam_exec's option seteuid The basic script /usr/local/bin/test_pam_foo.sh : #!/bin/sh id -u >> /tmp/test_pam_foo id -ru >> /tmp/test_pam_foo Unfortunately, I get all the time 0 as the effective id and real id. Am I missing something? As alternative, I know the existence of pam_script, not to be confused with pam-script (HowTos)