« Authentification SSH multi-facteur avec OATH (OTP / HOTP) et clés publiques SSH » : différence entre les versions

De Linux Server Wiki
Aller à la navigation Aller à la recherche
(Page créée avec « <pre> apt install libpam-oath oathtool </pre> Générez un secret hexadécimal <pre> $ head -10 /dev/urandom | sha512sum | cut -b 1-16 234197a7d5ef5c16 </pre> /etc/users… »)
 
Aucun résumé des modifications
Ligne 27 : Ligne 27 :
Puis désactivez l'authentification par password unix en commentant la ligne <code>@include common-auth</code> :
Puis désactivez l'authentification par password unix en commentant la ligne <code>@include common-auth</code> :
<pre>#@include common-auth</pre>
<pre>#@include common-auth</pre>
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 :
<pre>
ChallengeResponseAuthentication yes
UsePAM yes
PermitRootLogin yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no
</pre>
Notez qu'on passe <code>PermitRootLogin yes</code> (par défaut c'est <code>without-password</code>). Si vous ne vous loguerez pas directement en root, passez <code>PermitRootLogin no</code>.

Version du 5 juin 2021 à 15:58

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.