Hello again,
I have now tested different configurations, and it is actually quite easy to require password+YubiKey for some users and just passwd for others. All this is accomplished with
pam_succeed_if.so module along with some specific control values for PAM.
First, create group
yubikey-passwd-auth. Also, have the YubiKey mapping file ready (mine is in
etc/security/yubikey.map). Beware, if the user has no YubiKey mapping, and YubiKey-login is enforced, the user has no way to log in!
I created a file
/etc/pam.d/yubikey-passwd-auth:
Code:
# PAM configuration file for password+YubiKey authentication, if the user
# is in group yubikey-passwd-auth
# Skip the following rules if user is not in the specified group
auth [success=2 default=ignore] pam_succeed_if.so quiet user notingroup yubikey-passwd-auth
# Perform YubiKey authentication and die if this fails
auth requisite pam_yubico.so id=XX authfile=/etc/security/yubikey.map
# Check the password returned from the pam_yubico module, declare authentication done
# if this succeeds, die if it fails
auth [success=done default=die] pam_unix.so use_first_pass
And, the following code must be added to a sevice file in
/etc/pam.d/:
Code:
@include yubikey-passwd-auth
This code must be added just before the pam_unix.so call, or before the
@include common-auth line (or similar).
You can go even further and configure your system so that:
- Users in yubikey-passwd-auth authenticate with passwd+Yubikey
- Users in yubikey-auth can authenticate with Yubikey, without password
- Other users use only password
For this, the
yubikey-auth file would look like this:
Code:
# PAM configuration file for YubiKey authentication, if the user is in group yubikey-auth
# Skip the following rule if user is not in the specified group
auth [success=1 default=ignore] pam_succeed_if.so quiet user notingroup yubikey-auth
# Perform YubiKey authentication
auth [success=done default=die] pam_yubico.so id=XX authfile=/etc/security/yubikey.map
How does this method look like? Are there any security considerations? Configuring two-factor authentication with PAM seems very elegant solution to me, as Yubico PAM module can be stacked with any other authentication module. There is also no need to modify the Yubico PAM module to support complex configurations.
- Mikko