Ubuntu - SSH Login Benachrichtigung
Um jedes Mal, wenn sich jemand von einer nicht erlaubten IP-Adresse an einem Server per SSH anmeldet, eine Benachrichtigung zu bekommen kann man seine /etc/ssh/sshrc so erweitern:
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
logger -t ssh-wrapper $USER login from $ip
# Allowed adresses: 192.168.123.123 and 111.222.333.444
if [ "$ip" != "192.168.123.123" ] && [ "$ip" != "111.222.333.444" ]
then
# Send a mail
echo "User $USER just logged in from $ip" | mail -s "MyServer: SSH login successfull" me@example.com
# Send a push notification to a smartphone
curl \
--silent --output /dev/null \
-X POST https://api.pushbullet.com/v2/pushes \
--header 'Access-Token: myaccesstoken' \
--header 'Content-Type: application/json' \
--data-binary "{\"type\": \"note\", \"title\":\"MyServer - SSH Login\", \"body\": \"User $USER just logged in from $ip\"}"
fi