Secure SSH Settings
So sshd wasn’t set up on my new Jessie netinstall, so I decided to start it up:
$> sudo service ssh start I also learned that if openssh isn’t installed on the system, that won’t do anything. So I installed the Debian metapackage openssh, and knew that it would start now. But then again, let’s take this opportunity to learn systemd. There’s a great cheatsheet put out by the Fedora project that compares sysvinit commands and transposes them to systemd commands. So, to get sshd started I executed:
$> sudo systemctl start sshdCool. But now, we have to secure our ssh/ implementation and augment the paltry defaults that it ships with.
The crypto
Key exchange
Read the link above if you’re interested in the reasoning behind what comes next. Otherwise, implement the next few things to follow.
In /etc/ssh/sshd_config:
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256In /etc/ssh/ssh_config:
# Github needs diffie-hellman-group-exchange-sha1 some of the time but not
# always.
#Host github.com
# KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
Host *
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256For /etc/ssh/moduli if it exists:
$> awk '$5 > 2000' /etc/ssh/moduli > "${HOME}"/moduli"
$> wc -l "${HOME}/moduli"
$> mv "${HOME}/moduli" /etc/ssh/moduliIf it doesn’t:
$> ssh-keygen -G "${HOME}/moduli" -b 4096
$> ssh-keygen -T /etc/ssh/moduli -f "${HOME}/moduli"
$> rm "${HOME}/moduli"Authentication
In /etc/ssh/sshd_config:
Protocol 2
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
PasswordAuthentication no
ChallengeResponseAuthentication no
PubkeyAuthentication yes
AllowGroups ssh-userIn /etc/ssh/ssh_config:
Host *
PasswordAuthentication no
ChallengeResponseAuthentication no
PubkeyAuthentication yes
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v1@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-ed25519,ssh-rsaTo clean out any old short insecure keys:
$> cd /etc/ssh
$> rm ssh_host_*key*
$> ssh-keygen -t ed25519 -f ssh_host_ed25519_key < /dev/null
$> ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key < /dev/nullTo generate new keys:
$> ssh-keygen -t ed25519 -o -a 100
$> ssh-keygen -t rsa -b 4096 -o -a 100By the way, the -o switch:
Causes ssh-keygen to save SSH ‘Protocol 2’ private keys using the new OpenSSH format rather than the more compatible PEM format. The new format has incereased resistance to brute-force password cracking but is not supported by versions of OpenSSH prior to 6.5. Ed25519 keys always use the new private key format.To add group ssh-user:
$> sudo groupadd ssh-user
$> usermod -a -G ssh-user *username*Symmetric ciphers for data transmission encryption
In /etc/ssh/sshd_config:
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
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.comIn /etc/ssh/ssh_config:
Host *
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
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.comConclusion
There are many unorthodox/ ways and many sidechannels/ by which someone can compromise your data transmisson security/integrity. These defaults however provide a solid foundation of security when it comes to ssh. There is much much more to come however.