Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a log file or any service to report the latest login attempts which have failed due to username/password miss match. Is there such utility available for CentOS? (built-in is preferred)

My second question, and more generally, I need a log file of penetration attempts to my server. Ideally, this log should contain all attempts including logins, httpd activities, and other conventional open ports.

share|improve this question

migrated from Sep 22 '12 at 9:19

This question came from our site for professional and enthusiast programmers.

answer to second question: take a look at OSSEC. – quanta Sep 22 '12 at 10:49
This thread is moved from Stackoverflow after I asked the question in Serverfault. Here is the threads discussing the second question. – ahmad Sep 22 '12 at 10:58
up vote 6 down vote accepted

The question is here offtopic, but a very short answer: maybe you should just check /var/log/secure (e.g. grep for "failed").

share|improve this answer
It is actually the answer to my first question. I'll ask the second in ServerFault. Thanks. – ahmad Sep 22 '12 at 7:41

In Linux, the last command shows successful login attempts and displays session information (pts, source, date and length).

The lastb command records all bad login attempts. Both share the same man page, but the difference is that last reads the binary /var/log/wtmp file, and lastb reads the /var/log/btmp file by default.

The range of these files depends on your log rotation schedule, but it should span a few weeks. Most distributions will rotate /var/log/wtmp monthly, so you can read a previous record, usually listed as /var/log/wtmp.1 by specifying the file with the -f parameter... last -f /var/log/wtmp.1

share|improve this answer
+1 for the lastb – ahmad Sep 23 '12 at 11:36

This is a old thread but I got similar task like this,so in my case this is a log entry

Nov 15 17:14:47 megatron sshd[4768]: Failed password for git from port 49227 ssh2

So we can do it like this,if we are sure user is static

MESSAGE="Failed password for git"
grep -i "$MESSAGE" "$LOG

In case if we know on the per user basis

if [ -n "$1" ]
MESSAGE="Failed password for $NEWUSER"
grep -i "$MESSAGE" "$LOG"

So script should execute like

[root@megatron bash1]# ./ git

OR more easier approach

MESSAGE="Failed password for"
grep -i "$MESSAGE" "$LOG"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.