Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to log every SSH login attempts, both successful and not, to my FreeBSD server to a file, and daily mail this log to root.

I could accomplish something like this by parsing /var/log/auth.log, but a) this contains more than login attempts, and b) it could be turned over since yesterday's run. Is there a more direct way of doing this; for instance a hook in SSHd or login configuration to log each login?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

The default is to log to the AUTH facility. You can change the facility that sshd logs to with the SyslogFacility configuration option.

SyslogFacility LOCAL7

Then configure your syslogd to write local7.* to it's own file by adding

local7.*     /var/log/local7.log

to the syslogd configuration file. Tell syslogd to reread it's config file by sending it a HUP signal do the same for sshd and you should have sshd messages being sent to it's own file.

share|improve this answer
    
Thank you! :-) This is one possible solution. I also found another; PAM scripting -- see my own answer. –  poplitea Nov 29 '11 at 14:34
add comment

I stumbled upon this blog-post that describes multiple solutions to my question. Among other things it mentions log-parsing and, interestingly, PAM scripting through pam_exec. This enables me to run my own script on every login.

I think this is the most flexible solution to my problem, although Iain's previous answer probably is less invasive and also solves my problem.

share|improve this answer
add comment

Your Answer

 
discard

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.