sshhardeninglinux
MDstable
NoteSnippetChecklistPlaybook
SSH — Hardening & Configuration sécurisée
Configuration sshd_config durcie pour serveurs Linux
checklistbeginner 2025-05-10 2 min read
sshhardeninglinuxsysadminsecurite
Configuration /etc/ssh/sshd_config
bash
# Backup avant modificationsudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak# Editer la configsudo nano /etc/ssh/sshd_config
bash
Variables
{{USER}}
# ============================================# /etc/ssh/sshd_config — Configuration durcie# ============================================# Port non-standard (changer la valeur)Port 2222# Désactiver login rootPermitRootLogin no# Authentification par clé uniquementPasswordAuthentication noChallengeResponseAuthentication noUsePAM yes# Protocole et chiffrementProtocol 2KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctrMACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com# Limites de connexionMaxAuthTries 3MaxSessions 5LoginGraceTime 30ClientAliveInterval 300ClientAliveCountMax 2# Restriction utilisateurs/groupesAllowUsers {{USER}}# AllowGroups sshusers# Désactiver fonctionnalités inutilesX11Forwarding noAllowAgentForwarding noAllowTcpForwarding noPermitTunnel noPermitEmptyPasswords no# BannièreBanner /etc/ssh/banner.txt# LoggingLogLevel VERBOSESyslogFacility AUTH
Génération de clés SSH
bash
Variables
{{USER}}
{{SERVER_IP}}
# Générer paire de clés Ed25519 (recommandé)ssh-keygen -t ed25519 -C "{{USER}}@{{SERVER_IP}}" -f /.ssh/id_ed25519# Copier la clé sur le serveurssh-copy-id -i /.ssh/id_ed25519.pub -p 2222 {{USER}}{{SERVER_IP}}# Test de connexionssh -i /.ssh/id_ed25519 -p 2222 {{USER}}{{SERVER_IP}}# Vérifier fingerprint du serveur (première connexion)ssh-keyscan -p 2222 {{SERVER_IP}} | ssh-keygen -lf
Appliquer et tester
bash
# Vérifier la config AVANT de recharger (évite le lockout !)sudo sshd -t# Recharger sans couper les sessions activessudo systemctl reload sshd# Vérifier le statutsudo systemctl status sshd
Fail2ban — Protection brute force
bash
# Installer fail2bansudo apt install fail2ban -y# Config /etc/fail2ban/jail.localsudo tee /etc/fail2ban/jail.local << 'EOF'DEFAULTbantime 3600findtime 600maxretry 5backend systemdsshdenabled trueport 2222logpath sshd_logsmaxretry 3bantime 86400EOFsudo systemctl enable --now fail2bansudo fail2ban-client status sshd
Checklist SSH Hardening0/11
OPS·BRAIN v1.09 notes · SysAdminlocal