How to send root SSH login notification on Debian

You probably have thought about an additional step of security, namely the ability to send notifications when you log in to your root account.
This point will be considered in this article.


The simplest answer to sending one-line messages via gmail is to use ssmtp.

Firstly, login as root:

su - root

Then, install ssmtp with the following commands:

apt-get update
apt-get install ssmtp

Adjust ssmtp.conf configuration file:

nano /etc/ssmtp/ssmtp.conf


Open the file ~/.bashrc in a text editor.

nano ~/.bashrc

And append the following lines:

IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"
NOW=$(date +"%e %b %Y, %a %r")

echo -e 'Subject: SSH Login Notification\n\nSomeone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | ssmtp



We will be happy to hear your thoughts

Leave a reply