PAM exec stdout issue

Loris1634 asked:

I am having an issue with a dead simple python script; called with pam_exec.

I added a line at the end of that file /etc/pam.d/common-session :

session optional /bin/python /usr/local/bin/

The script contains a simple print "Hello world"

Obviously, this is not working, but I do not understand why. The script is not printing anything when I su user or simply su, but when I start a new shell and manually execute python /usr/local/bin/ it is working.

Did I miss something ?
Thanks for reading !

My answer:

The pam_exec(8) man page tells why:

           Per default the output of the executed command is written to
           /dev/null. With this option, the stdout output of the executed
           command is redirected to the calling application. It's in the
           responsibility of this application what happens with the output.
           The log option is ignored.

So you need to add stdout to the line:

session optional stdout /bin/python /usr/local/bin/

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.