Audit de sécurité Linux : checklist CIS Benchmark étape par étape

Publié le 15 janvier 2026

Linux
Sécurité
Compliance

Un serveur Linux par défaut n'est pas sécurisé. Le CIS Benchmark (Center for Internet Security) fournit un référentiel de bonnes pratiques reconnu pour durcir votre système. Cet article vous guide pas à pas dans l'audit et l'application des recommandations CIS.

Plan

  • Qu'est-ce que le CIS Benchmark ?
  • Installation des outils d'audit
  • Audit automatisé avec CIS-CAT Pro et alternatives
  • Recommandations critiques à appliquer
  • Scripts d'automatisation
  • Conclusion

Qu'est-ce que le CIS Benchmark ?

Le CIS Benchmark est un ensemble de bonnes pratiques de sécurité pour systèmes d'exploitation, applications et services cloud. Pour Linux, il couvre :

  • Configuration système (kernel, filesystem, boot)
  • Services réseau (SSH, NTP, DNS)
  • Gestion des utilisateurs et permissions
  • Logging et auditing
  • Maintenance et updates

Niveaux de sécurité :

  • Level 1 : Recommandations de base, impact minimal sur les performances
  • Level 2 : Sécurité renforcée, peut impacter certains services

Les benchmarks CIS sont disponibles pour :

  • Debian 11/12
  • Ubuntu 20.04/22.04/24.04
  • RHEL 8/9
  • Rocky Linux 8/9
  • AlmaLinux 8/9

Installation des outils d'audit

Lynis : scanner de sécurité open source

# Installation Debian/Ubuntu
apt install lynis

# Installation RHEL/Rocky
dnf install lynis

# Lancer un audit complet
lynis audit system

# Audit avec rapport détaillé
lynis audit system --report-file /var/log/lynis-report.dat

Lynis génère un score de durcissement et liste les recommandations prioritaires.

OpenSCAP : conformité CIS automatisée

# Installation Debian/Ubuntu
apt install libopenscap8 ssg-debian ssg-debderived

# Installation RHEL/Rocky
dnf install openscap-scanner scap-security-guide

# Lister les profils disponibles
oscap info /usr/share/xml/scap/ssg/content/ssg-debian12-ds.xml

# Scanner avec le profil CIS Level 1
oscap xccdf eval \
  --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
  --results /tmp/oscap-results.xml \
  --report /tmp/oscap-report.html \
  /usr/share/xml/scap/ssg/content/ssg-debian12-ds.xml

Le rapport HTML identifie les écarts avec le benchmark CIS.


Audit automatisé avec CIS-CAT Pro et alternatives

CIS-CAT Pro (gratuit pour usage personnel)

  1. Télécharger depuis CIS WorkBench
  2. Extraire l'archive
  3. Lancer l'audit :
cd Assessor-CLI
./Assessor-CLI.sh -i -rd /tmp/cis-results/ -html

Le rapport HTML classe les recommandations par criticité.

Alternative open source : CIS-Audit

# Cloner le repository
git clone https://github.com/finalduty/cis_benchmarks_audit
cd cis_benchmarks_audit

# Lancer l'audit
./cis_audit.sh

# Rapport généré dans ./reports/

Recommandations critiques à appliquer

1. Durcissement SSH

# /etc/ssh/sshd_config
Protocol 2
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
PermitEmptyPasswords no
X11Forwarding no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers <votre_user>
LogLevel VERBOSE

# Redémarrer SSH
systemctl restart sshd

2. Désactiver les services inutiles

# Lister les services actifs
systemctl list-units --type=service --state=running

# Désactiver services non nécessaires
systemctl disable --now avahi-daemon
systemctl disable --now cups
systemctl disable --now bluetooth

3. Configuration du firewall

# UFW (Debian/Ubuntu)
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw enable

# firewalld (RHEL/Rocky)
firewall-cmd --set-default-zone=drop
firewall-cmd --zone=public --add-service=ssh --permanent
firewall-cmd --reload

4. Audit système avec auditd

# Installation
apt install auditd audispd-plugins  # Debian/Ubuntu
dnf install audit                    # RHEL/Rocky

# Configuration /etc/audit/rules.d/cis.rules
-w /etc/passwd -p wa -k identity
-w /etc/group -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /var/log/lastlog -p wa -k logins
-w /var/run/faillock -p wa -k logins
-a always,exit -F arch=b64 -S adjtimex,settimeofday -k time-change
-a always,exit -F arch=b64 -S sethostname,setdomainname -k system-locale
-w /etc/selinux/ -p wa -k MAC-policy

# Recharger les règles
augenrules --load

# Démarrer auditd
systemctl enable --now auditd

5. Permissions fichiers critiques

# Scripts CIS pour fixer les permissions
chmod 644 /etc/passwd
chmod 644 /etc/group
chmod 600 /etc/shadow
chmod 600 /etc/gshadow
chmod 600 /boot/grub/grub.cfg
chmod 600 /etc/ssh/sshd_config
chown root:root /etc/passwd /etc/group /etc/shadow /etc/gshadow

6. Désactiver IPv6 (si non utilisé)

# /etc/sysctl.d/99-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

# Appliquer
sysctl -p /etc/sysctl.d/99-disable-ipv6.conf

7. Hardening kernel

# /etc/sysctl.d/99-cis-hardening.conf
kernel.randomize_va_space = 2
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.tcp_syncookies = 1

# Appliquer
sysctl -p /etc/sysctl.d/99-cis-hardening.conf

Scripts d'automatisation

Script de vérification CIS Level 1

#!/bin/bash
# cis-check.sh - Vérification rapide CIS Level 1

echo "=== CIS Benchmark Quick Check ==="

# 1. SSH hardening
echo -n "SSH: PermitRootLogin no... "
grep -q "^PermitRootLogin no" /etc/ssh/sshd_config && echo "✓" || echo "✗"

echo -n "SSH: PasswordAuthentication no... "
grep -q "^PasswordAuthentication no" /etc/ssh/sshd_config && echo "✓" || echo "✗"

# 2. Firewall actif
echo -n "Firewall actif... "
(systemctl is-active ufw >/dev/null 2>&1 || systemctl is-active firewalld >/dev/null 2>&1) && echo "✓" || echo "✗"

# 3. Auditd running
echo -n "Auditd actif... "
systemctl is-active auditd >/dev/null 2>&1 && echo "✓" || echo "✗"

# 4. Permissions /etc/shadow
echo -n "/etc/shadow permissions... "
[[ $(stat -c %a /etc/shadow) == "600" ]] && echo "✓" || echo "✗"

# 5. Services inutiles désactivés
echo -n "Avahi désactivé... "
systemctl is-enabled avahi-daemon >/dev/null 2>&1 && echo "✗" || echo "✓"

# 6. Kernel hardening
echo -n "Kernel: randomize_va_space=2... "
[[ $(sysctl -n kernel.randomize_va_space) == "2" ]] && echo "✓" || echo "✗"

echo -n "Kernel: IP forwarding disabled... "
[[ $(sysctl -n net.ipv4.ip_forward) == "0" ]] && echo "✓" || echo "✗"

echo ""
echo "Lancer un audit complet avec : lynis audit system"

Script d'application automatique

⚠️ Attention : Ce script modifie la configuration système. Testez en environnement de dev d'abord.

#!/bin/bash
# cis-apply.sh - Application automatique des recommandations CIS Level 1

set -e

echo "=== Application CIS Benchmark Level 1 ==="
echo "ATTENTION : Ce script modifie la configuration système"
read -p "Continuer ? (yes/no) " -r
[[ ! $REPLY =~ ^yes$ ]] && exit 0

# Backup configuration
mkdir -p /root/cis-backup-$(date +%Y%m%d)
cp /etc/ssh/sshd_config /root/cis-backup-$(date +%Y%m%d)/
cp /etc/sysctl.conf /root/cis-backup-$(date +%Y%m%d)/

# 1. SSH hardening
echo "Durcissement SSH..."
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/^#*X11Forwarding.*/X11Forwarding no/' /etc/ssh/sshd_config
sed -i 's/^#*MaxAuthTries.*/MaxAuthTries 3/' /etc/ssh/sshd_config
systemctl restart sshd

# 2. Permissions fichiers critiques
echo "Correction permissions..."
chmod 644 /etc/passwd
chmod 644 /etc/group
chmod 600 /etc/shadow
chmod 600 /etc/gshadow

# 3. Kernel hardening
echo "Hardening kernel..."
cat > /etc/sysctl.d/99-cis.conf << EOF
kernel.randomize_va_space = 2
kernel.dmesg_restrict = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.tcp_syncookies = 1
EOF
sysctl -p /etc/sysctl.d/99-cis.conf

# 4. Auditd
echo "Installation auditd..."
if command -v apt >/dev/null; then
    apt install -y auditd audispd-plugins
elif command -v dnf >/dev/null; then
    dnf install -y audit
fi

cat > /etc/audit/rules.d/cis.rules << EOF
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /var/log/lastlog -p wa -k logins
EOF
augenrules --load
systemctl enable --now auditd

# 5. Désactiver services inutiles
echo "Désactivation services..."
for svc in avahi-daemon cups bluetooth; do
    systemctl disable --now $svc 2>/dev/null || true
done

echo ""
echo "✓ Application terminée"
echo "Vérifiez avec : ./cis-check.sh"
echo "Backups dans : /root/cis-backup-$(date +%Y%m%d)/"

Conclusion

Le CIS Benchmark fournit une base solide pour sécuriser vos serveurs Linux. L'audit régulier (mensuel minimum) garantit le maintien de votre posture de sécurité. Les outils comme Lynis et OpenSCAP automatisent la vérification, tandis que les scripts permettent un déploiement rapide sur plusieurs serveurs.

Points clés à retenir :

  • Commencez par CIS Level 1 (impact minimal)
  • Auditez avant d'appliquer les changements
  • Testez en environnement de dev
  • Documentez vos écarts justifiés
  • Automatisez les vérifications périodiques
Besoin d'aide sur ce sujet ?

Notre équipe d'experts est là pour vous accompagner dans vos projets.

Contactez-nous

Articles similaires qui pourraient vous intéresser