Project

General

Profile

Support #591

Updated by Daniel Curtis about 9 years ago

This is guide for hardening an SSH server. 

 * *WARNING*: You will need a recent OpenSSH version. It should work with 6.5 but I have only tested 6.6; you can check the current version by running: 
 <pre> 
 ssh -V 
 </pre> 

 h2. Key Exchange 

 * Add a strong Key Exchange: 
 <pre> 
 echo 'KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256' >> /etc/ssh/sshd_config 
 </pre> 

 * Open /etc/ssh/moduli if exists, and delete lines where the 5th column is less than 2000. 
 <pre> 
 awk '$5 > 2000' /etc/ssh/moduli > "${HOME}/moduli" 
 wc -l "${HOME}/moduli" 
 mv "${HOME}/moduli" /etc/ssh/moduli 
 </pre> 
 #* If @wc -l@ is empty, create it: 
 <pre> 
 ssh-keygen -G "${HOME}/moduli" -b 4096 
 ssh-keygen -T /etc/ssh/moduli -f "${HOME}/moduli" 
 rm "${HOME}/moduli" 
 </pre> 

 h2. Authentication 

 * Edit the sshd config file: 
 <pre> 
 vi /etc/ssh/sshd_config 
 </pre> 
 #* And modify the following parameters to only use SSHv2 and ed25519 and rsa key algorithms: 
 <pre> 
 Protocol 2 
 HostKey /etc/ssh/ssh_host_ed25519_key 
 HostKey /etc/ssh/ssh_host_rsa_key 
 </pre> 

 h2. Client Authentication 

 * edit the sshd config file: 
 <pre> 
 vi /etc/ssh/sshd_config 
 </pre> 
 #* And modify the following parameters to disable password based logins: 
 <pre> 
 PasswordAuthentication no 
 ChallengeResponseAuthentication no 
 PubkeyAuthentication yes 
 </pre> 

 h2. Symmetric Ciphers 

 *NOTE*: For some reason I could not get the aes256-gcm@openssh.com and aes128-gcm@openssh.com ciphers to work on OpenSSH 6.6. 
 * Add strong Symmetric Ciphers: 
 <pre> 
 echo 'Ciphers chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr' chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr' >> /etc/ssh/sshd_config 
 </pre> 

 h2. Message Authentication Codes 

 * Add strong Message Authentication Codes: 
 <pre> 
 echo 'MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com' >> /etc/ssh/sshd_config 
 </pre> 

 h2. Generate Strong Client Keypairs 

 * Generate strong client ssh keypairs: 
 <pre> 
 ssh-keygen -t ed25519 -o -a 512 
 ssh-keygen -t rsa -b 4096 -o -a 512 
 </pre> 

 h2. Resources 

 * https://stribika.github.io/2015/01/04/secure-secure-shell.html

Back