When you have access to your private key file, use it for quick login. When you are on the go, use your Yubikey OTP and your password.
Tutorial: https://developers.yubico.com/yubico-pam/YubiKey_and_SSH_via_PAM.html
-
Install yubico pam module:
sudo apt-get install libpam-yubico
-
Create file
/etc/yubikey_mappings
with the allowed users and their corresponding YubiKey token IDs (first 12 characters of OTP):username1:vvabcdefghij username2:vvabcdefghij
-
Get a new API-id from https://upgrade.yubico.com/getapikey/ and adjust file
/etc/pam.d/sshd
to request YubiKey OTP. Paste this line at the very beginning of the file:auth required pam_yubico.so id=12345 authfile=/etc/yubikey_mappings
You can add the
debug
argument as stated here: https://developers.yubico.com/yubico-pam/Manuals/pam_yubico.8.html -
In
/etc/ssh/sshd_config
set the following configurations:PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication yes UsePAM yes
PermitRootLogin no
is set just for security reasons.ChallengeResponseAuthentication yes
andUsePAM yes
will ask for YubiKey and then for password.- One could also set
PasswordAuthentication yes
andChallengeResponseAuthentication no
, which would take Password+OTP as one single password string, without explicitly asking for YubiKey.