22 points · by bengtan · 16y ago · 17 comments
I realise there are things that can defend against this (ie. IP access control, moving ssh to a non-standard port number, root login disallowed etc.) and that, statistically, they will not guess a password correctly anytime soon. I'm not interested in discussion of these techniques (though others may be).
However, I think, psychologically, it can be a bit unpleasant knowing that people are attacking your servers. Do you guys worry about this? Even when knowing the probability of a successful guess is negligible?
http://denyhosts.sourceforge.net/
The out of the box config options are pretty decent, giving a few attempts to most accounts but only one wrong password for root before blocking the IP address.
I have it send email notifications to my support ticket tracking system, which automatically sorts them so I can see how heavily I'm being attacked at any given time, or if one VM in particular is being targeted. (One VM has been a particular target over the holidays, so I just turned off SSH entirely and access it using the Xen console for now.)
The down side of having a good understanding of how much you're under attack is that it is a bit disturbing. In reality, I know that I could just leave SSH running on all my VMs, but turning it off when someone's targeting one of them reduces the flow of scary emails. The most disturbing thing is how many machines these guys must have already compromised, since as soon as you block one IP address another steps in.
I use ssh keys only. I've disabled the use of passwords for any account other than root on the console, and for that, I use a very long random password which is stored very carefully, encrypted with a long passphrase. This is only needed in emergencies.
Be careful to protect your ssh keys (long passphrases and ssh-agent), and it's probably a good idea to use hashes in your known_hosts file rather than addresses so malware can't find all the hosts you can access.
But since then I haven't spotted a single brute-force attempt on any of my boxes...
Like most of the other posters, I ended up taking the following steps to cut down on the problem: (1) disable root login at all, (2) switch sshd from port 22 to another, random port for listening (that alone cut the attacks way, way down), (3) disable all password based logins; only key-based logins work now, (4) limit the users who could login remotely at all to a very small group (you can create a group just for this purpose, enroll two or three admins and edit your sshd_config file to allow only members of that group to login at all), (5) use rate-limiting in iptables to freeze out any attacking ip after two or three failed attempts in a minute.
A link with lots of detailed methods to handle brute force attacks and their pros and cons, in case anybody wants it: http://la-samhna.de/library/brutessh.html
[1] http://www.mollison.us/blog/2009/10/18/how-hard-is-it-to-bru...
There's no excuse for root logins and passwords are harder to manage and less secure.
something like this
http://jonsbraindump.blogspot.com/2007/09/iptables-rules-to-...
-N SSH_RECENT
-A INPUT -m state --state NEW -p tcp --dport 22 -j SSH_RECENT
-A SSH_RECENT -m recent --set --name SSH
-A SSH_RECENT -m recent --update --seconds 60 --hitcount 3 --name SSH -j DROP+1. If/when there's an sshd remote exploit/worm, it will probably only scan port 22.
"AllowUsers" is good too.
And, port knocking if you don't mind the hassle.
That said, my preferred solution is openvpn.