A mail per valid SSH session
You want to be notified when someone connects on your server with ssh? Add this sshrc config file to your ssh config directory (/etc/ssh):
emailfrom=root@`hostname`
emailto=<_your address here_>
fulluser="$USER@"`hostname`
date822=`date -R`
ldate=`date "+%A %e %B %Y a %Hh%M %Z"`
host_ip="`echo $SSH_CONNECTION | awk '{print $1}'`"
host_dns="`host ${host_ip}`"
echo -e "\
From: $emailfrom
To: $emailto
Subject: [SSHRC] ssh session - $USER
Date: $date822
User-Agent: sshrc
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hello,
A ssh session version $SHLVL opened,
with local user $fulluser,
$ldate,
from host $SSH_CONNECTION.
host DNS : $host_dns
- --
sshrc" | /usr/sbin/sendmail -t
Add your email to the emailto variable, test and modify to your needs.
Thanks to Léa for her ssh post on this.
