Sunday, 2 June 2013

Need Linux login e-mail notifications?

Need a fast way to receive notifications of logins to your Linux server?

Append the following to: /etc/profile


Create a file /usr/local/login and change the permissions: chmod 755 /usr/local/login

You will need to install mutt, apt-get install mutt on Debian/Ubuntu should work fine, once done paste the following in the /usr/local/login file (change the e-mail address):

# Login script, append full script path to /etc/profile, requires mutt            
# By ONMS.Net


report_date=$(date -R)
server_ip=$(ifconfig eth0 | grep inet | head -n 1 | sed 's/:/ /g' | awk '{ print $3 }')
message="Login Date: $report_date - Users currently logged in: $whoisloggedin"
echo $message | mutt -s "Login detected to server $server_ip" $email_to

I'll be adding a script soon to allow for login data reporting to, this should allow for easier e-mails and sms notifications of server logins.

No comments:

Post a Comment