Post

Notification ssh login

vim sshrc to /etc/ssh/

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
#!/bin/bash

# Get login user
user=$(getent passwd `who` | head -n 1 | cut -d : -f 1)
if [ "" = "$user" ]; then
   user="default"
fi
# Get login user's IP
ip=${SSH_CLIENT%% *}
echo $ip
if [ "$ip" = "" ]; then
   ip="default"
fi
# Get login time
time=$(date +%F-%k:%M)
# Serverip
server=`ifconfig eth1|sed -n '2p'|awk -F ":" '{print $2}'|awk '{print $1}'`
if [ "$server" = "" ]; then
   server="default"
fi

# push to ntfy

curl -u user:password -d "ssh has a new login, $user $time $ip" https://ntfy.sh/mytopic >> /dev/logs/sshlogin.log 2>&1 &

This post is licensed under CC BY 4.0 by the author.