Ssh – Are there additional ways to protect SSH connections besides firewall and RSA Keys

centoslinuxSecurityssh

Sometimes I don't have a static IP and need to administrate my web server remotely. I'm looking for any additional layers of protection I could add to make opening port 22 safer.

Currently I have disabled root password login via SSH. It requires RSA key to login (the private key is stored on a usb smart card).

Are there any known risks with my configuration if port 22 was opened to the public? Besides port 22, iptables only has port 80 and port 443 open to the public.

I'm using a Windows computer to connect to Centos 6 Linux with Putty.

Are there any additional statements I can add to the firewall or SSH config to further limit access to port 22 to only my specific computer so that the port doesn't appear open to people scanning ports? I'm using iptables for the firewall currently.

Best Answer

Your existing configuration seems very secure. However, there are additional things you can use to restrict access.

Port knocking can be used to keep the port closes most of the time. This is implemented using iptables. There are daemons which can be used, or the rules can be implemented entirely in iptables as described in the Shorewall documentation.

If tcp wrappers is enabled. A couple of ruless like the following in /etc/hosts.allow will notify you whenever a remote connection is made to the deamon. The first rule lets local connections work silently, adjust the ip address range as appropriate. The second rule prevents access from addresses which reverse to a number of country TLD, and emails a message for each successful connection. It could be noisy, if you don't use Port Knocking.

sshd :          10.0.0.0/8 192.168.0.0/24 

sshd :          ALL \
            EXCEPT .ar .au .br .by .cl .co .cz .do .eg .gt \
                .id .il .in .jp .ma .mx .nl .pe .pk .pl .pt \
                .ro .rs .ru .sa .sg .tr .tw .ua .vn .za \
                .ae .at .bg .gh .hr .hu .ke .kz .lt .md \
                .my .no .sk .uy .ve : \
            spawn (/bin/echo "SSH connection to %N from %n[%a] allowed" | \
                /usr/bin/mailx -s "SSH Allowed" you@example.com)

fail2ban rules can be used to temporarily blacklist hosts which are trying to brute force your server. I've seen occasional attempts when I have had ssh exposed to the Internet.