Email Alert When User Login Using SSH
On web servers, you may need to get email alert when someone login to your server using SSH. To do this edit file
1 |
vi ~/.bashrc |
Add
1 |
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`" you@your-domain.com |
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
1 |
echo 'ALERT - Root Shell Access (' `hostname` ') on:' `date` `who` >> /var/log/user-logins |
See SSH