Réduisez la surface d’attaque en configurant sshd de manière restrictive.
objectifs d’apprentissage
- Désactiver mot de passe.
- Interdire root direct.
- Appliquer Match blocs.
prérequis
- Accès root au serveur.
- Éditeur sur /etc/ssh/sshd_config.
notions clés
- PasswordAuthentication no.
- PermitRootLogin prohibit-password.
- Match User/Address.
démonstration guidée
étape 1
Modifier sshd_config et recharger le service.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
echo 'PermitRootLogin prohibit-password' | sudo tee -a /etc/ssh/sshd_config
sudo systemctl reload sshd || sudo service ssh reload
étape 2
Exemple de bloc Match pour un sous-réseau d’admin.
sudo tee -a /etc/ssh/sshd_config << 'EOF'
Match Address 203.0.113.0/24
AllowTcpForwarding no
X11Forwarding no
EOF
sudo systemctl reload sshd || true
exercice
Désactivez ChallengeResponseAuthentication et vérifiez avec ssh -v.
correction
Option additionnelle.
echo 'ChallengeResponseAuthentication no' | sudo tee -a /etc/ssh/sshd_config
ssh -v user@203.0.113.10 true || true
quiz éclair
- Quelle directive interdit l’authentification par mot de passe ?
- a) PasswordAuthentication no
- b) PubkeyAuthentication no
- c) PermitRootLogin no