Email Alert When User Login Using SSH

On web servers, you may need to get email alert when someone logs in to your server using SSH. To do this edit file

vi ~/.bashrc

Add

echo "ALERT - Bash shell access by user \"`whoami`\" to server $HOSTNAME  on  `date` "  | mail -s  "Alert:  Shell access detected from user \"`whoami`\" from IP_Address: `who | cut -d"(" -f2 | cut -d")" -f1`" [email protected]

In above, replace [email protected] with your actual email address. You need a mail server installed on your server for this to work.

If you want to log to a file, add

echo 'ALERT - Root Shell Access (' `hostname` ') on:' `date` `who` >> /var/log/user-logins

See SSH

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *