I'm trying to check if a user who connects to a linux server via SSH is authentificated using Active Directory (Centrify).
In case he uses a local account (located in /etc/passwd), I need to display a warning asking him to use his Active Directory account and then prompt login again.
My first attempt was using PAM module pam_script inside /etc/pam.d/login to execute a script that checks if the current username exists in /etc/passwd whenever a user log in, display a warning if found and call the login command again.
I added the following line to /etc/pam.d/login
session required pam_script.so runas=root
This line execute a script file located in /etc/security/onsessionopen which contain:
#!/bin/sh
username=$1
if [ $(grep -c '^'$username':' /etc/passwd) = 1 ]
then
echo "Warning, please user your AD credentials"
login
fi
But the same scenario didn't work in /etc/pam.d/sshd.
When using SSH the script does run but doesn't display text or prompt for login.
Any thoughts ? Thank you