Get an e-mail every time someone logs in via SSH

If you want an e-mail every time someone logs in via SSH to your machine follow these easy steps.

1. Edit /etc/pam.d/sshd. Add the two following lines anywhere.

#Send email alert on each SSH login
session optional pam_exec.so /usr/bin/email_who.sh

2. Create and edit /usr/bin/email_who.sh. Add the following lines.

#!/bin/bash
tail /var/log/auth.log | mail -s "SSH Login: `hostname -f`" -t someone@server.org

3. Make the e-mail script executable.

sudo chmod 755 /usr/bin/email_who.sh

Original post can be found here: http://www.webhostingtalk.com/showthread.php?t=924848.

Post a comment:






«-- back

What is this?

This is an entry posted to the Snakeblog on July 12, 2011.

This entry is part of the categories Server and Ubuntu

Tags: pam_exec and ssh

Latest entries in the snakeblog

This page uses the Perfect 'Holy Grail' 3 Column Liquid Layout.


Creative Commons License
This work is licensed under a
Creative Commons License.