Too many ssh unauthorized login attempts - how to prevent?

Posted July 22, 2014 12.8k views

This appears daily in logwatch under PAM. Is there anyway to prevent it? I already have configured sshd to prevent root login, and use fail2ban.

unknown ( 189 Time(s)
root ( 75 Time(s)
root ( 74 Time(s)
root ( 55 Time(s)
root ( 50 Time(s)
root ( 50 Time(s)
root ( 50 Time(s)
root ( 50 Time(s)
root ( 50 Time(s)
root ( 50 Time(s)

I guess I could switch login to certificate only, but that limits how I can access my server.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Personally the first thing I do one all my servers is to disable password logins and only connect using SSH key pairs. Disabling root login, which you’ve already done, is also a good step. Many people also change the port that the SSH daemon listens on from port 22 to something else.

You could set IP table rules that will drop all connections to your SSH port except from specific IP addresses. Though that obviously limits where you can log in from. Setting up port knocking is another option.

You might also just want to tweak your fail2ban configuration to be a bit more aggressive. Check out these tutorials for more information on fail2ban:

How To Install and Use Fail2ban on Ubuntu 14.04

How Fail2ban Works to Protect Services on a Linux Server

by Justin Ellingwood
When you start a new server, there are a few steps that you should take every time to add some basic security and set a solid foundation. In this guide, we'll walk you through the basic steps necessary to hit the ground running with Ubuntu 14.04.

Thank you Andrew.

Is it possible to block all traffic from China? Does anyone recommend that?