Simple method your to notify by e-mail whenever there is SSH access to your server by adding several lines into
You will need mailer which works public internet environment.
Debian/Ubuntu, you can install simply by command,
sudo apt install mailutils
1. Open your
- only for current user
- Apply to all users
sudo nano /etc/profile
2. Edit and add script
IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)" HOSTNAME=$(hostname) NOW=$(date +"%e %b %Y, %a %r") echo 'Someone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | mail -s 'SSH Login Notification' <mail address>
<mail address> as yours.
Copy & paste into
Save & Exit.
3. Test SSH login
If you access server, you will recieve notification e-mail to configured address like below: