天天看點

通過郵件監控使用者登入linux系統

通過郵件監控使用者登入linux系統

将監控腳本放在/etc/ssh路徑下,當有使用者登入進來的時候會自動執行

#cat /etc/ssh/sshrc

#!/bin/bash

#登入者的使用者名

user=$USER

#登入者ip

ip=`echo $SSH_CLIENT | awk '{print $1}'`

#登陸時間

time=$(date +%F%t%k:%M)

#伺服器ip

server=`/sbin/ifconfig eth0|sed -n '2p' |awk -F: '{print $2}' | awk '{print $1}'`

#發送郵件

echo -e "Someone logged in to The TMS NFS Machine, the information below \n\nTime:      $time  \n\nUser:        $user \n\nLogin ip:     $ip \n" | mail -s "Login in Server:$server" [email protected]

#chmod a+x /etc/ssh/sshrc

繼續閱讀