serveur:ssh

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
serveur:ssh [2020/04/06 22:36] – [Fichier de configuration du serveur] d2airserveur:ssh [2024/11/01 20:06] (Version actuelle) – [Fichier de configuration du client] d2air
Ligne 1: Ligne 1:
 ====== Configuration de SSH ====== ====== Configuration de SSH ======
-<note warning> 
-Cette page est en cours d'écriture. 
-</note> 
 ===== Générer de l'entropie ===== ===== Générer de l'entropie =====
 ==== RNG-Tools ==== ==== RNG-Tools ====
Ligne 10: Ligne 7:
 </code> </code>
 Pour configuer ''rng-tools'' il faut éditer le fichier ''/etc/default/rng-tools'', mais c'est normalement inutile celui-ci pouvant reconnaître seul les sources d'entropie. Il faudra surtout éviter de le configurer avec ''/dev/urandom'' comme source (voir [[https://lwn.net/Articles/525459/|cet article]]). Pour configuer ''rng-tools'' il faut éditer le fichier ''/etc/default/rng-tools'', mais c'est normalement inutile celui-ci pouvant reconnaître seul les sources d'entropie. Il faudra surtout éviter de le configurer avec ''/dev/urandom'' comme source (voir [[https://lwn.net/Articles/525459/|cet article]]).
 +
 +Si vous avez un module TPM vous pouvez aussi ajouter ''tpm-rng'' dans le fichier de configuration /etc/initramfs-tools/modules :
 +<code>
 +sudo vi /etc/initramfs-tools/modules
 +sudo update-initramfs -u
 +sudo systemctl reboot
 +</code>
 ===== Installer Open-SSH Server ===== ===== Installer Open-SSH Server =====
 <code> <code>
Ligne 20: Ligne 24:
 ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N "" < /dev/null ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N "" < /dev/null
 ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N "" < /dev/null ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N "" < /dev/null
-ssh-keygen -moduli-4096.candidates -b 4096 +ssh-keygen -M generate -O bits=4096 moduli-4096.candidates 
-ssh-keygen -T moduli-4096 -f moduli-4096.candidates+ssh-keygen -M screen -f moduli-4096.candidates moduli-4096
 mv moduli moduli-`date +"%Y%m%d"`.bak mv moduli moduli-`date +"%Y%m%d"`.bak
 mv moduli-4096 moduli mv moduli-4096 moduli
-mv sshd_config sshd_config-original-`date +"%Y%m%d"`.bak +copier les configurations personnalisées comme ci-dessous dans /etc/ssh/sshd_config.d/ et /etc/ssh/ssh_config.d/
-vi sshd_config +
-modifier la config du serveur comme ci-dessous +
-vi ssh_config +
-# modifier la config du client comme ci-dessous+
 systemctl restart ssh.service systemctl restart ssh.service
 </code> </code>
 ==== Fichier de configuration du serveur ==== ==== Fichier de configuration du serveur ====
 Cette configuration désactive la connexion par l'utilisateur root, elle interdit l'authentification par un mot de passe et la remplace par une clef. Cette configuration désactive la connexion par l'utilisateur root, elle interdit l'authentification par un mot de passe et la remplace par une clef.
-<file sh sshd_config> +Copiez la configuration suivante dans un fichier se terminant par .conf dans le répertoire : /etc/ssh/sshd_config.d/ 
-# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $ +<file sh sshd_config_local.conf>
- +
-# This is the sshd server system-wide configuration file See +
-# sshd_config(5) for more information. +
- +
-# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin +
- +
-# The strategy used for options in the default sshd_config shipped with +
-# OpenSSH is to specify options with their default value where +
-# possible, but leave them commented Uncommented options override the +
-# default value. +
 Port 1234 Port 1234
 #AddressFamily any #AddressFamily any
Ligne 57: Ligne 46:
 # Ciphers and keying # Ciphers and keying
 #RekeyLimit default none #RekeyLimit default none
-#https://www.securiteinfo.com/cryptographie/renforcer-cryptage-ssh.shtml +Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-gcm@openssh.com,aes128-ctr 
-Ciphers aes256-ctr,aes192-ctr,aes128-ctr,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-gcm@openssh.com +HostKeyAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256 
-KexAlgorithms diffie-hellman-group18-sha512,diffie-hellman-group16-sha512,diffie-hellman-group14-sha256,curve25519-sha256@libssh.org +KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256 
-MACs umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com +MACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com 
-HostKeyAlgorithms ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ssh-rsa,ssh-dss,rsa-sha2-256,rsa-sha2-512+PubkeyAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256 
 +HostbasedAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256 
 +CASignatureAlgorithms sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256 
 +GSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512- 
  
 # Logging # Logging
Ligne 168: Ligne 161:
 </file> </file>
 ==== Fichier de configuration du client ==== ==== Fichier de configuration du client ====
 +Copiez la configuration suivante dans un fichier se terminant par .conf dans le répertoire : /etc/ssh/ssh_config.d/
 +<file sh ssh_config_local.conf>
 +Host *
 +    PasswordAuthentication yes
 +    PubkeyAuthentication yes
 +    ChallengeResponseAuthentication no
 +    SendEnv LANG LC_*
 +    HashKnownHosts yes
 +##  faster connexion
 +    GSSAPIAuthentication no
 +    GSSAPIKeyExchange no
 +    GSSAPIRenewalForcesRekey no
 +    GSSAPIDelegateCredentials no
 +##    
 +    Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-gcm@openssh.com,aes128-ctr
 +    KexAlgorithms sntrup761x25519-sha512@openssh.com,gss-curve25519-sha256-,curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256,gss-group16-sha512-,diffie-hellman-group16-sha512
 +    MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com
 +    RequiredRSASize 4096
 +    HostKeyAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256
 +    CASignatureAlgorithms sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256
 +    GSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-
 +    HostbasedAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256
 +    PubkeyAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256
 +</file>
 +Les sites [[https://www.ssh-audit.com/hardening_guides.html|SSH Audit]] et [[https://www.securiteinfo.com/cryptographie/renforcer-cryptage-ssh.shtml|Sécurité Info]] proposent des exemples de configurations adaptées.
 +==== Redémarrer SSH ====
 <code> <code>
-mv ssh_config ssh_config-original-`date +"%Y%m%d"`.bak +systemctl restart ssh.service
-vi ssh_config+
 </code> </code>
-<file sh ssh_config> 
-# This is the ssh client system-wide configuration file.  See 
-# ssh_config(5) for more information.  This file provides defaults for 
-# users, and the values can be changed in per-user configuration files 
-# or on the command line. 
- 
-# Configuration data is parsed as follows: 
-#  1. command line options 
-#  2. user-specific file 
-#  3. system-wide file 
-# Any configuration value is only changed the first time it is set. 
-# Thus, host-specific definitions should be at the beginning of the 
-# configuration file, and defaults at the end. 
- 
-# Site-wide defaults for some commonly used options.  For a comprehensive 
-# list of available options, their meanings and defaults, please see the 
-# ssh_config(5) man page. 
- 
-Host * 
-#   ForwardAgent no 
-#   ForwardX11 no 
-#   ForwardX11Trusted yes 
-#   PasswordAuthentication yes 
-#   HostbasedAuthentication no 
-#   GSSAPIAuthentication no 
-#   GSSAPIDelegateCredentials no 
-#   GSSAPIKeyExchange no 
-#   GSSAPITrustDNS no 
-#   BatchMode no 
-#   CheckHostIP yes 
-#   AddressFamily any 
-#   ConnectTimeout 0 
-#   StrictHostKeyChecking ask 
-#   IdentityFile ~/.ssh/id_rsa 
-#   IdentityFile ~/.ssh/id_dsa 
-#   IdentityFile ~/.ssh/id_ecdsa 
-#   IdentityFile ~/.ssh/id_ed25519 
-#   Port 22 
-#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc 
-#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com 
-#   EscapeChar ~ 
-#   Tunnel no 
-#   TunnelDevice any:any 
-#   PermitLocalCommand no 
-#   VisualHostKey no 
-#   ProxyCommand ssh -q -W %h:%p gateway.example.com 
-#   RekeyLimit 1G 1h 
-PasswordAuthentication yes 
-PubkeyAuthentication yes 
-ChallengeResponseAuthentication no 
-SendEnv LANG LC_* 
-HashKnownHosts yes 
-# faster connexion 
-GSSAPIAuthentication no 
-GSSAPIKeyExchange no 
-GSSAPIRenewalForcesRekey no 
-GSSAPIDelegateCredentials no 
-# 
-Ciphers aes256-ctr,aes192-ctr,aes128-ctr,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-gcm@openssh.com 
-KexAlgorithms diffie-hellman-group18-sha512,diffie-hellman-group16-sha512,diffie-hellman-group14-sha256,curve25519-sha256@libssh.org 
-MACs umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com 
-HostKeyAlgorithms ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ssh-rsa,ssh-dss,rsa-sha2-256,rsa-sha2-512 
-</file> 
  • serveur/ssh.1586226966.txt.gz
  • Dernière modification : 2020/04/06 22:36
  • de d2air