Ludo blog

en
Aug 2017
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

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.

by ludovic Bellier on Sat Aug 7 00:02:31 2004 (Viewed: 6991 / 0 comments )
  |   RSS  |   RSS2  |   Atom  |   Source  |   Edit
Comments not allowed anymore on this post