How to get an email notification when someone logs into SSH

One neat trick, is to receive an email when someone logs into your VPS via SSH. Generally, only few people should have SSH access to the VPS. The rest should access your website / email / control panels /etc as needed.

To get an email when someone logs into SSH, do the following:

Login to your VPS via SSH.

Edit /etc/profile  in your favourate editor. vi is the most common Linux / UNIX editor.

Navigate to the bottom of the file, and add the following

Add the following:

echo 'SSH (localhost) on:' `date` `who` |
 mail -s "Alert: Access from `who | cut -d"(" -f2 | cut -d")" -f1`" you@yourdomain

Now login to your VPS again, and you’ll receive an email 🙂

P.S. Change you@yourdomain to your own email address

via

How to get an email notification when someone logs into SSH – Knowledgebase – SoftDux.

Annunci