I'd like to see if somebody has been trying to log-in by brute-force into my Ubuntu 12.04 server over SSH. How can I see if such activities have been taking place?
I'd like to see if somebody has been trying to log-in by brute-force into my Ubuntu 12.04 server over SSH. How can I see if such activities have been taking place?
All login attempts are logged to
/var/log/auth.log
.1. Filter for brute-force interactive SSH logins
Open a terminal, and type the below; if it's longer than 1 page you will be able to scroll up and down; type
q
to exit:Here's a real example from one of my VPSs:
2. Look for failed connections (i.e. no login attempted, could be a port scanner, etc.):
Use this command:
Example:
How to reduce failed/brute-force login attempts
I would argue that monitoring logs is a weak solution especially if you have a weak password on an account. Brute attempts often try at least hundreds of keys per minute. Even if you have a cron job set to email you of brute attempts, it could be hours before you get to your server.
If you have a public-facing SSH server, you need a solution that kicks in long before you can be hacked.
I would strongly recommend
fail2ban
. Their wiki says what it does better than I can.Getting protection from it is as simple as
sudo apt-get install fail2ban
.By default as soon as somebody has three failed attempts, their IP gets a five minute ban. That sort of delay essentially halts a SSH brute force attempt but it's not going to ruin your day if you forget your password (but you should be using keys anyway!)
Short Answer: To keep track of the failed attempts, you should just view the log file
/var/log/auth.log
without using any pattern matching commands because those patterns are not exhaustive. Then, to mitigate it, you could use tools like fail2ban.Long Answer: There are many ways for invalid logins to happen. For example, an attacker might try some default usernames and passwords like the default "kali" username and "kali" password on Kali Linux. (It is a technique German hackers used extensively during the Cold War era. Read The Cuckoo's Egg if you are interested.)
Say if you remove the "kali" user, the grep commands above won't catch this: