BASH script to email when someone logins to my server?


New Member
I remember seeing this somewhere and want to add it to what I am working on. It would send an email anytime someone would login to your VPS via SSH. It looked really simple but I didn't bookmark it.

Anyone know how to accomplish this?

D. Strout

Resident IPv6 Proponent
Quick Google turns up this: How do I set up an email alert when a ssh login is successful? (AskUbuntu, though I imagine it applies to other OSes)


New Member
A more general solution is to use in the appropriate /etc/pam.d file adding the line

session required onsessionopen=/etc/
This will execute the script file on login. You can use this hook to grab logins to any service that uses pam for authentication which includes most non-vhost services on linux.