I was trying to use pam_exec.so on Ubuntu to call a script, prompt for user input and allow the user to log in through SSH if the script exits with an exit code of 0. I was unable to get this to work. So I wrote a simple script as follows to test pam_exec.so and see if the problem was with my original script. However I am getting the same issues even with this simple script.
/usr/local/bin/test.sh
#!/bin/bash
echo -n "Please enter your name:"
read name
echo "Hello $name"
I called it by including the following line after
Then I changed the above script as follows to exit with an exit code of 1 if no input is given.
#!/bin/bash
echo -n "Please enter your name:"
read name
if [ -z "$name" ]
then
exit 1
else
echo "Hello $name"
exit 0
fi
Then I am unable to SSH into the system (screenshot below) even when I enter the correct password and I do not see any output of the script.
So what I want to know is how can I correct this problem and use pam_exec.so to run a script, get user input, and allow ssh authorization only if that script exits with an exit code of 0?
@include common-auth
in /etc/pam.d/sshd
auth required pam_exec.so stdout /usr/local/bin/test.sh
But when I SSH into this system as seen below, I do not get a prompt to enter any input. As soon as I enter the password, I get logged in. However, the output of the script is visible.


Asked by Nilushan Costa
(340 rep)
Nov 7, 2017, 05:49 AM
Last activity: Jul 26, 2025, 07:04 AM
Last activity: Jul 26, 2025, 07:04 AM