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:
1
su - root
Then, install ssmtp
with the following commands:
1
2
apt-get update
apt-get install ssmtp
Adjust ssmtp.conf
configuration file:
1
nano /etc/ssmtp/ssmtp.conf
1
2
3
4
5
6
root=postmaster
FromLineOverride=YES
mailhub=smtp.gmail.com:465
AuthUser=testEmailFrom@gmail.com
AuthPass=testpass
UseTLS=YES
Open the file ~/.bashrc
in a text editor.
1
nano ~/.bashrc
And append the following lines:
1
2
3
4
5
IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"
HOSTNAME=$(hostname)
NOW=$(date +"%e %b %Y, %a %r")
echo -e 'Subject: SSH Login Notification\n\nSomeone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | ssmtp testEmailTo@gmail.com