hardeninglinuxCIS
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ésPermitRootLogin noPasswordAuthentication no # clés uniquementPubkeyAuthentication yesAuthorizedKeysFile ssh/authorized_keysPermitEmptyPasswords noMaxAuthTries 3LoginGraceTime 30ClientAliveInterval 300ClientAliveCountMax 2AllowUsers {{USER}} deploy # liste blanche expliciteProtocol 2X11Forwarding noAllowTcpForwarding no # sauf si tunnel nécessaireBanner /etc/ssh/banner# Chiffres forts uniquement (SSH >= 7.x)KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.orgHostKeyAlgorithms ssh-ed25519,rsa-sha2-512,rsa-sha2-256Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.comMACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com# Appliquersystemctl restart sshdsshd -t # tester la config avant restart
Kernel — sysctl
bash
# /etc/sysctl.d/99-hardening.conf# Réseau — protection anti-spoofing et attaquesnetipv4confallrp_filter 1netipv4confdefaultrp_filter 1netipv4confallaccept_source_route 0netipv4confallaccept_redirects 0netipv4confallsecure_redirects 0netipv4confallsend_redirects 0netipv4icmp_echo_ignore_broadcasts 1netipv4icmp_ignore_bogus_error_responses 1netipv4tcp_syncookies 1 # protection SYN floodnetipv4confalllog_martians 1netipv6confallaccept_redirects 0netipv6confallaccept_ra 0 # désactiver si IPv6 inutilisé# Mémoire — protection exploitskernelrandomize_va_space 2 # ASLR completkerneldmesg_restrict 1 # limiter accès dmesgkernelkptr_restrict 2 # cacher les adresses kernelfsprotected_hardlinks 1fsprotected_symlinks 1fssuid_dumpable 0 # pas de core dump SUID# Appliquersysctl -p /etc/sysctl.d/99-hardening.confsysctl --system
Gestion des paquets et services
bash
# Supprimer les services inutilessystemctl disable cupssystemctl disable avahi-daemonsystemctl disable bluetoothsystemctl disable nfs-serversystemctl disable rpcbind# Lister les services actifssystemctl list-units --type=service --state=running# Supprimer les paquets inutiles (Debian/Ubuntu)apt remove telnet rsh-client rsh-redone-client nis talkapt autoremove# Mettre à jour régulièrementapt update && apt upgrade -y# Ou configurer les mises à jour automatiques :apt install unattended-upgradesdpkg-reconfigure unattended-upgrades
Audit des comptes et accès
bash
# Comptes sans mot de passeawk -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 suspectsfind -perm -4000 -o -perm -2000 2>/dev/null | grep -v "^/usr\|^/bin\|^/sbin"# Fichiers world-writablefind -xdev -type f -perm -002 2>/dev/null# Cronjobs de tous les utilisateursfor user in cut -f1 -d: /etc/passwd; doecho "=== $user ==="; crontab -u $user -l 2>/dev/nulldone# Clés SSH autoriséesfind /home -name authorized_keys -exec cat ; 2>/dev/nullcat /root/.ssh/authorized_keys 2>/dev/null
PAM — Politique de mots de passe
bash
# Installer pwqualityapt install libpam-pwquality# /etc/security/pwquality.confminlen 14dcredit -1 # au moins 1 chiffreucredit -1 # au moins 1 majusculelcredit -1 # au moins 1 minusculeocredit -1 # au moins 1 caractère spécialmaxrepeat 3 # pas plus de 3 répétitionsgecoscheck 1 # vérifier que le mdp ne contient pas le nom# /etc/pam.d/common-password (Debian)password requisite pam_pwqualityso retry3password required pam_pwhistoryso remember24 # historique 24 mdp
Audit avec Lynis
bash
# Installerapt install lynis# ougit clone https//github.com/CISOfy/lynis# Audit completlynis 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 statusiptables -L -n | grep -c ACCEPT# Services en écoutess -tulnp | grep -v "127.0.0.1\|::1"# Dernières connexionslast | head -20lastb | head -10 # échecs de connexion# Intégrité des fichiers systèmedebsums -c 2>/dev/null # Debian/Ubuntu — fichiers modifiésrpm -Va 2>/dev/null # RHEL/CentOS# AIDE — tripwire opensourceaide --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