Guide de sécurisation des accès SSH sur Debian


Sommaire
1. Backup de la configuration d'origine
2. Configuration du fichier
3. Personnalisation du message d’accueil
4. Appliquer la configuration



1. Backup de la configuration d'origine

Avant de commencer, effectuez une sauvegarde du fichier original :

cd /etc/ssh/
cp sshd_config sshd_config.0



2. Configuration du fichier

Éditez le fichier sshd comme suit :

nano /etc/ssh/sshd_config


Les parties de texte surligné sont modifiées.

Include /etc/ssh/sshd_config.d/*.conf
Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
AllowUsers User
LoginGraceTime 2m
PermitRootLogin no
StrictModes yes
MaxAuthTries 3
MaxSessions 3

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
KbdInteractiveAuthentication no

# Kerberos options
KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

UsePAM yes

#AllowAgentForwarding yes
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
ClientAliveInterval 900 #60
ClientAliveCountMax 0 #3
UseDNS no
#PidFile /var/run/sshd.pid
MaxStartups 3:5:10
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
banner /etc/issue

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server



3. Personnalisation du message d’accueil

Il est recommandé de personnaliser le message d’avertissement à la connexion

nano /etc/issue


| *******************************
| * Avertissement de sécurité *
| *******************************
|
| Vous vous apprêtez à accéder à un serveur sécurisé.
| Toute activité sur ce serveur est enregistrée et peut être surveillée.
|
| L'accès non autorisé à ce serveur est strictement interdit et peut
| entraîner des sanctions légales.
|
| Veuillez-vous assurer que vous êtes autorisé à vous connecter à ce système.
| Si vous n'êtes pas autorisé, déconnectez-vous immédiatement.
|
| Merci de votre coopération.
|
| *******************************



4. Appliquer la configuration

Redémarrez le service pour appliquer la configuration

Systemctl restart ssh