I have a CentOS 7 machine where I'd like to display a message when authentication fails during sudo. I tried to do this by adding a pam_echo line in /etc/pam.d/sudo.
For testing, I created a file, /etc/security/foo, that contains the string 'bar'.
This is my sudo pam stack, /etc/pam.d/sudo:
auth include system-auth
auth optional pam_echo.so file=/etc/security/foo
account include system-auth
password include system-auth
session optional pam_keyinit.so revoke
session required pam_limits.so
For some reason, I don't see this output of pam_echo when I fail to authenticate.
$ sudo ls
[sudo] password for steve:
Sorry, try again.
[sudo] password for steve:
Sorry, try again.
[sudo] password for steve:
sudo: 3 incorrect password attempts
I tested the sudo pam stack with pamtester and got the expected result after entering the wrong password.
$ pamtester sudo steve authenticate
Password:
bar
Likewise, I got no output when entering the correct password.
$ pamtester sudo steve authenticate
Password:
pamtester: successfully authenticated
It seems that sudo is somehow overriding or interfering with the pam output. Why would sudo need to do this? Can I change the behavior of sudo so the output gets through?