Authentification SSH multi-facteur avec OATH (OTP / HOTP) et clés publiques SSH

De Linux Server Wiki
Aller à la navigation Aller à la recherche
apt install libpam-oath oathtool

Générez un secret hexadécimal

$ head -10 /dev/urandom | sha512sum | cut -b 1-16
234197a7d5ef5c16

/etc/users.oath :

# Option User Prefix Seed
HOTP/T30/6 user - 234197a7d5ef5c16

Sécurisez l'accès aux clés secrètes :

chmod 600 /etc/users.oath
chown root:root /etc/users.oath

To enable oath for a specific service only, like ssh, you can edit the file /etc/pam.d/sshd and add at the beginning of the file the following line: Pour activer l'authentification oath pour ssh, ajoutez cette ligne au début du fichier /etc/pam.d/sshd :

auth required pam_oath.so usersfile=/etc/users.oath window=30 digits=6

Puis désactivez l'authentification par password unix en commentant la ligne @include common-auth :

#@include common-auth

Note : si vous ne commentez pas cette ligne, vous devrez entrer, en plus de l'OTP, le password unix pour vous loguer

Modifiez la configuration du serveur openssh :

ChallengeResponseAuthentication yes
UsePAM yes
PermitRootLogin yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no

Notez qu'on passe PermitRootLogin yes (par défaut c'est without-password). Si vous ne vous loguerez pas directement en root, passez PermitRootLogin no.