Knowledgebase

SSH Login Email Alerts

The examples below send an email when someone logs into your server. For this to work, your server must be able to send mail using the mail command.

CentOS

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

Append the following lines:

==================================

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' YOUR_EMAIL_ADDRESS


 

Ubuntu/Debian

 

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

 

Append the following lines:

=================================

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' YOUR_EMAIL_ADDRESS




  • linux, ssh

Was this answer helpful?

2 Users Found This Useful

Related Articles

Configure Static IP on Centos 6 Static IP on Centos 6## Configure eth0## vi /etc/sysconfig/network-scripts/ifcfg-eth0... Monitor Server Logs in Real-Time with "Log.io" Log.io is a small application build on Node.js and Socket.io for monitoring real time Linux server logs through web interface.On... How to configure VPN VPN SETUP To use the VPN on Mac you can use the following steps. Download and install OpenVPN client from... How-to extend a root LVM partition online There is also a quick remedy for the emergency situation when your root partition runs out of disk space. There is a feature specific to... Install Taskwarrior (terminal based todo application) on Ubuntu/Centos   Taskwarrior is Free and Open Source Software that manages your TODO list from your command line. It is flexible, fast, efficient,...