---
title: "Hardening Linux — CIS Benchmark"
domain: security
subdomain: hardening
type: checklist
tags: [hardening, linux, CIS, security, audit, sysctl, ssh]
difficulty: intermediate
status: stable
updated: "2025-05-10"
---
## SSH

```bash
# /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
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.tcp_syncookies = 1                  # protection SYN flood
net.ipv4.conf.all.log_martians = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_ra = 0              # désactiver si IPv6 inutilisé

# Mémoire — protection exploits
kernel.randomize_va_space = 2                # ASLR complet
kernel.dmesg_restrict = 1                    # limiter accès dmesg
kernel.kptr_restrict = 2                     # cacher les adresses kernel
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
fs.suid_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_pwquality.so retry=3
password required pam_pwhistory.so remember=24   # 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.
</Tip>
