I get a lot of SSH connection attempt from different IP on my server (with different username). 1 to 5 per seconds. It look like a brute force attack. What can I do to prevent that? Block the IP? change the SSH port? Something else?
Thanks!
I get a lot of SSH connection attempt from different IP on my server (with different username). 1 to 5 per seconds. It look like a brute force attack. What can I do to prevent that? Block the IP? change the SSH port? Something else?
Thanks!
The DenyHosts package is one that is freely available and will block "bots" from attempting repeated attacks to your ssh port.
http://denyhosts.sourceforge.net/
Great software for blocking them.
Note: it's also included in many distros by default.
Changing the ssh port solves it quite well. Never had any problems (it is just too costy for brute forcers to scan the range once there are so many machines with the defaut port).
Don't change the port (permanently) it's pointless against any sophisticated attack and only creates obstruction. Good security is in good policy, not obscurity. If you can consider limiting access to a set of known IPs, if you can't consider denyhosts, as mentioned above. You should also talk to your ISP about this, maybe there is an attack on a segment o their network and they are unaware.
So I did a combination of :
You might find http://www.snowman.net/projects/ipt_recent/ useful for this - you can do something like this:-
If you are setting lots of failures from different IP addresses your server is being targeted by a distributed brute force attack. some key points:
So, steps to securing your SSH server:
Requiring key based authentication doesn't really secure the ssh server, it secures authentication. If you only rely on key based authentication to secure the server, you open yourself up to any potential exploits against openssh. If a 0day exploit was released against openssh and you are running ssh on port 22 and relying on keys to "secure" your server, it will be hacked within hours.
A much better practice is to not even allow people to connect to the ssh server in the first place.
+1 for changing the port.
If you always have a static IP, block all access from everything but that IP.
It's difficult to block IPs if either you have a dynamic IP, or your brute force attack is coming from multiple IPs.
If the IPs are common, i.e. it's always a range of 10 IP addresses doing the attack, find out which ISP owns them and submit an abuse report with log entries.
another +1 for changing ports - at a bare minimum. Otherwise, set up a VPN and firewall everything except the VPN connection. It's the best of both worlds in my opinion.
If it is a single (or only a few) remote IPs trying to log in, you can install a host route for the IP(s), with a gateway of 127.0.0.1 (the loopback interface). That way, they cannot establish a TCP session, but you run the risk of running out of kernel resources (at 1-5 attempts per second, it should be OK, though).