This is relatively trivial to do using groups, with no changes to the source.
I simply have a group on the system called "yubikey" - anyone in that group will need to use their Password + Yubikey to login. Users not in that group only need to use their password (in my case, LDAP-based passwords). I only do this for sshd.
To do that I have the following in /etc/sshd :
Code:
auth [success=1 default=ignore] pam_succeed_if.so quiet user notingroup yubikey
auth required pam_yubico.so id=16 authfile=/etc/yubikeyid
auth required pam_ldap.so try_first_pass
# Standard Un*x authentication.
#@include common-auth
The first line tells PAM to skip the next line if the user is not in the group "yubikey".
The second line, which only gets used if the user IS in the yubikey group is a standard pam_yubico config.
The third line is a standard pam_ldap config - obviously if you're not using LDAP you'll need to modify this a bit.
The 4th (commented-out) line is what was in the file previously, and in my case had to be commented out to avoid it doing local auth. It also gives you an idea of where in a default config these lines have to go.