After having hardened Apache during the previous post over here, we’ll take a look at OpenSSH.
Why ?
‘Cause if you secure your web server, it’s good to enforce some “good” rules on your SSH server too, unless securing your web server would be pointless
Content
In order to set up a “hardened” OpenSSH, just edit your /etc/ssh/sshd_config
, after having backup’ed your current configuration (cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
), and paste the following (please, do adapt it to what you actually need / want) :
Once you have adapted and paste the content above, you’ll have to get rid of the moduli the less secure.
In order to achieve this, please copy / paste the BASH snippet below (taken and one-line’d from here) :
Let’s do the same with your keys ( DANGEROUS OPERATION ) :
Now, you have to manually add the sessions that will have the right to connect through SSH :
(# addgroup ssh)
# usermod -G ssh <yourSession>
Only if you went through all the previous actions correctly, you can check your OpenSSH configuration with :
# sshd -t
If it’s okay too, you may now reload the SSH daemon :
(# service ssh reload)
# systemctl reload ssh
Now DON’T CLOSE YOUR CURRENT REMOTE SESSION, and try to open a new one
Also, if everything is still okay, you can delete the old backups !
# rm {sshd_config,moduli}.backup
EDIT 2017-11-26 : I’ve done the same thing for my OpenSSH Client, you should take a look at it over here !
Sources
-
Default OpenSSH
ssh[d]_config
files packaged in Debian -
How To Configure Custom Connection Options for your SSH Client