PDA

View Full Version : Emails Upon SSH Logins



TheFerrett
05-25-2008, 10:02 AM
If you're looking to be emailed when someone logs into your Managed Dedicated Server, you can do it thusly:

1) Log into your site via SSH.
2) Edit the bash file by typing vi /.bashrc.
3) At the end, add this line:

echo 'ALERT - Shell Access From [SERVERNAME] on:' `date` | mail -s "Alert: Shell [SERVERNAME] Access" yourname@yourdomain.com

That'll email you when someone logs in. I'd like to upgrade this script to add a date and an IP address, but I'm not sure how. If someone has any idea and could help, that would be coolness incarnate.

Danke,
T.F.

corvus
05-27-2008, 04:23 PM
Try this:

echo 'ALERT - Shell Access From [SERVERNAME] on:' `date +%Y-%m-%d-%H:%M:%S` from $SSH_CLIENT | mail -s "Alert: Shell [SERVERNAME] Access" yourname@yourdomain.com

date +%Y-%m-%d-%H:%M:%S