MDstable
NoteSnippetChecklistPlaybook

Hardening Linux — CIS Benchmark

Durcissement d'un serveur Linux selon les recommandations CIS

checklistintermediate 2025-05-10 4 min read
hardeninglinuxCISsecurityauditsysctlssh

SSH

bash
Variables
{{USER}}
# /etc/ssh/sshd_config — paramètres recommandés
PermitRootLogin no
PasswordAuthentication no # clés uniquement
PubkeyAuthentication yes
AuthorizedKeysFile ssh/authorized_keys
PermitEmptyPasswords no
MaxAuthTries 3
LoginGraceTime 30
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers {{USER}} deploy # liste blanche explicite
Protocol 2
X11Forwarding no
AllowTcpForwarding no # sauf si tunnel nécessaire
Banner /etc/ssh/banner
# Chiffres forts uniquement (SSH >= 7.x)
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org
HostKeyAlgorithms ssh-ed25519,rsa-sha2-512,rsa-sha2-256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
# Appliquer
systemctl restart sshd
sshd -t # tester la config avant restart

Kernel — sysctl

bash
# /etc/sysctl.d/99-hardening.conf
# Réseau — protection anti-spoofing et attaques
netipv4confallrp_filter 1
netipv4confdefaultrp_filter 1
netipv4confallaccept_source_route 0
netipv4confallaccept_redirects 0
netipv4confallsecure_redirects 0
netipv4confallsend_redirects 0
netipv4icmp_echo_ignore_broadcasts 1
netipv4icmp_ignore_bogus_error_responses 1
netipv4tcp_syncookies 1 # protection SYN flood
netipv4confalllog_martians 1
netipv6confallaccept_redirects 0
netipv6confallaccept_ra 0 # désactiver si IPv6 inutilisé
# Mémoire — protection exploits
kernelrandomize_va_space 2 # ASLR complet
kerneldmesg_restrict 1 # limiter accès dmesg
kernelkptr_restrict 2 # cacher les adresses kernel
fsprotected_hardlinks 1
fsprotected_symlinks 1
fssuid_dumpable 0 # pas de core dump SUID
# Appliquer
sysctl -p /etc/sysctl.d/99-hardening.conf
sysctl --system

Gestion des paquets et services

bash
# Supprimer les services inutiles
systemctl disable cups
systemctl disable avahi-daemon
systemctl disable bluetooth
systemctl disable nfs-server
systemctl disable rpcbind
# Lister les services actifs
systemctl list-units --type=service --state=running
# Supprimer les paquets inutiles (Debian/Ubuntu)
apt remove telnet rsh-client rsh-redone-client nis talk
apt autoremove
# Mettre à jour régulièrement
apt update && apt upgrade -y
# Ou configurer les mises à jour automatiques :
apt install unattended-upgrades
dpkg-reconfigure unattended-upgrades

Audit des comptes et accès

bash
# Comptes sans mot de passe
awk -F: '($2 == "" || $2 == "!") {print $1}' /etc/shadow
# Comptes avec UID 0 (root supplémentaires)
awk -F: '($3 == 0) {print $1}' /etc/passwd
# Binaires SUID/SGID suspects
find -perm -4000 -o -perm -2000 2>/dev/null | grep -v "^/usr\|^/bin\|^/sbin"
# Fichiers world-writable
find -xdev -type f -perm -002 2>/dev/null
# Cronjobs de tous les utilisateurs
for user in cut -f1 -d: /etc/passwd; do
echo "=== $user ==="; crontab -u $user -l 2>/dev/null
done
# Clés SSH autorisées
find /home -name authorized_keys -exec cat ; 2>/dev/null
cat /root/.ssh/authorized_keys 2>/dev/null

PAM — Politique de mots de passe

bash
# Installer pwquality
apt install libpam-pwquality
# /etc/security/pwquality.conf
minlen 14
dcredit -1 # au moins 1 chiffre
ucredit -1 # au moins 1 majuscule
lcredit -1 # au moins 1 minuscule
ocredit -1 # au moins 1 caractère spécial
maxrepeat 3 # pas plus de 3 répétitions
gecoscheck 1 # vérifier que le mdp ne contient pas le nom
# /etc/pam.d/common-password (Debian)
password requisite pam_pwqualityso retry3
password required pam_pwhistoryso remember24 # historique 24 mdp

Audit avec Lynis

bash
# Installer
apt install lynis
# ou
git clone https//github.com/CISOfy/lynis
# Audit complet
lynis audit system
# Score et recommandations dans /var/log/lynis.log
# Résumé
grep "Suggestion\|Warning" /var/log/lynis.log | head -30

Checklist rapide

bash
# Firewall actif ?
ufw status
iptables -L -n | grep -c ACCEPT
# Services en écoute
ss -tulnp | grep -v "127.0.0.1\|::1"
# Dernières connexions
last | head -20
lastb | head -10 # échecs de connexion
# Intégrité des fichiers système
debsums -c 2>/dev/null # Debian/Ubuntu — fichiers modifiés
rpm -Va 2>/dev/null # RHEL/CentOS
# AIDE — tripwire opensource
aide --check
💡 Tip —

Après hardening, tester avec nmap -sV -p- {{SERVER_IP}} depuis l'extérieur et relancer lynis audit system pour mesurer le score. Viser > 80/100. Documenter chaque déviation par rapport aux recommandations CIS avec la justification métier.

OPS·BRAIN v1.075 notes · Securitylocal