What measures can/should I take to make sure that security around my SSH server is absolutely impermeable?
This will be community wiki from the start, so lets see what people do to secure their servers.
|
|
Use public/private key pairs for authentication instead of passwords.
Now, the only possible way to SSH into the server is to use a key that matches a line in |
|||||||||||||||||
|
|
I would suggest:
|
|||||||||
|
|
Other answers provide security, but there is one thing you can do which will make your logs quieter, and make it less likely that you'll be locked out of your account: Move the server from port 22 to another one. Either at your gateway, or on the server. It doesn't increase the security, but does mean all the random internet scanners won't clutter up you log files. |
|||||||||||||||||
|
|
Make the sshd block client IP's that have failed to supply correct login information "DenyHØsts" can do this job quite effectively. I have this installed on all my Linux boxes that are in some way reachable from the great outside. This will make sure that force-attacks on the SSHD won't be effective, but remember (!) this way you can end up locking yourself out if you forget you password. This can be a problem on a remote server that you don't have access to. |
|||||
|
|
Enable two factor authentication with HOTP or TOTP. This is available from 13.10 onwards. This includes using public key authentication over password authentication as in another answer here, but also requires the user prove he holds his second-factor-device in addition to his private key. Summary:
More details on different configuration options are my blog post from last year: Better two factor ssh authentication on Ubuntu. |
||||
|
|
|
Here's one easy thing to do: install ufw (the "uncomplicated firewall") and use it to rate limit incoming connections. From a command prompt, type:
If ufw is not installed, do this and try again:
Many attackers will try to use your SSH server to brute-force passwords. This will only allow 6 connections every 30 seconds from the same IP address. |
|||||||||
|
|
If I want to have some additional security or need to access SSH servers deep inside some corporate network I setup a hidden service by using the anonymisation software Tor.
Furthermore I need Tor on my local host. If it is installed I can enter |
|||||
|
|
There is a Debian Administration article on this topic. It covers basic SSH server configuration and also firewall rules. This could be of interest also to hardened an SSH server. See there article: Keeping SSH access secure. |
|||||||||
|
|
My approach to SSH hardening is... complex. The following items are in terms of how I do it, from the edge-most border of my network(s) to the servers themselves.
My two-cents to securing SSH. Or, at least, my thoughts on approach. |
||||
|
|
|
You might want to checkout the FreeOTP app from RedHat instead of using Google Authenticator. Sometimes when updating the app, they lock you out! ;-) If you want to use other hardware tokens like a Yubikey or an eToken PASS or NG or if you have many users or many servers, you might want to use an opensource two factor authentication backend. Lately I wrote a howto about this. |
||||
|
|
|
I wrote a small tutorial on doing this recently. Basically, you need to be using PKI and my tutorial also shows how to use Two-Factor Authentication for even more security. Even if you use none of those things, there's also some tidbits about securing the server by removing weak cipher suites and other basics. https://joscor.com/blog/hardening-openssh-server-ubuntu-14-04/ |
||||
|
|
|
For large numbers of users/certificates consider LDAP integration. Large organizations use LDAP as a repository for user credentials and certificates stored on badges or fobs, whether the certificates are used for authentication or signing emails. Examples include openLDAP, openDJ, Active Directory, Oracle Universal Directory, IBM Directory Server, snareWorks... Computers and groups can also be managed in LDAP giving central credential management. That way help desks can have a one stop shop to deal with large populations. Here's a link to centOS integration: http://itdavid.blogspot.com/2013/11/howto-configure-openssh-to-fetch-public.html |
||||
|
|
|
You can also block based on country of origin using the geoIP database. Basically if you live in the US then there is no reason for somebody in Russia to connect to your SSH so they will be automatically blocked. The script can be found here: https://www.axllent.org/docs/view/ssh-geoip/ You can also add iptables commands to it (I did for my droplets) to auto drop all traffic to/from those IPs. |
|||||
|