mirror of
https://github.com/stylersnico/ssh-login-alert-telegram.git
synced 2026-06-15 08:02:54 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
## Alert via telegram when user logon via SSH
|
||||
|
||||
Work on all popular linux system (Debian <3, Ubuntu, Arch Linux etc..)
|
||||
|
||||

|
||||
|
||||
### Requirement
|
||||
- curl
|
||||
|
||||
Yes only this !
|
||||
|
||||
### Install
|
||||
1) Clone this repo or copy alert.sh for example in /root/:
|
||||
```cd /root/ && git clone https://github.com/MyTheValentinus/ssh-login-alert-telegram```
|
||||
|
||||
2) Edit two configuration variables by editing alert.sh:
|
||||
```editor alert.sh```
|
||||
|
||||
3) Add this script when user connect, edit bashrc, profile or openssh-server option etc..
|
||||
```sh deploy.sh```
|
||||
_(Don't forget to change the path of script if you use deploy.sh)_
|
||||
|
||||
4) Test it !
|
||||
|
||||
5) Start this project and tweet me (@MyTheValentinus) ! Thanks ;) <3
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Your USERID or Channel ID to display alert and key, we recommend you create new bot with @BotFather on Telegram
|
||||
USERID=""
|
||||
KEY=""
|
||||
|
||||
URL="https://api.telegram.org/bot$KEY/sendMessage"
|
||||
DATE="$(date "+%d %b %Y %H:%M")"
|
||||
|
||||
if [ -n "$SSH_CLIENT" ]; then
|
||||
CLIENT_IP=$(echo $SSH_CLIENT | awk '{print $1}')
|
||||
|
||||
SRV_HOSTNAME=$(hostname -f)
|
||||
SRV_IP=$(hostname -I | awk '{print $1}')
|
||||
|
||||
IPINFO="https://ipinfo.io/$CLIENT_IP"
|
||||
|
||||
TEXT="Connection from *$CLIENT_IP* as $USER on *$SRV_HOSTNAME* (*$SRV_IP*)
|
||||
Date: $DATE
|
||||
More informations: [$IPINFO]($IPINFO)"
|
||||
|
||||
curl -s -d "chat_id=$USERID&text=$TEXT&disable_web_page_preview=true&parse_mode=markdown" $URL > /dev/null
|
||||
fi
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "# Log connection" >> /etc/profile
|
||||
echo "sh /root/ssh-login-alert-telegram/alert.sh" >> /etc/profile
|
||||
Reference in New Issue
Block a user