Skip to content

✅A simple script for notification SSH access, exits and entries to the Server✅

Notifications You must be signed in to change notification settings

Ser4ph4/Bot-Telegram-SSH-Connection-Notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 

Repository files navigation

alt text

Bot-Telegram-SSH-Connection-Notify

✅A simple script for notification SSH access, exits and entries to the Server✅
Telegram Notifications on SSH Logins

1- Creating the BOT (its Free)

Search for the user "botfather". https://t.me/BotFather We create a new bot by sending "botfather" the following message: /newbot "botfather" will ask for the name of the bot.

2- Configuring the bot

Now, search for the newly created bot in your Telegram contacts. Next, start the bot by clicking on start or sending the message: /start. Next, open Postman or your Browser to the address shown below. Replace "TOKEN" with the token you got from "botfather" in the previous step:

https://api.telegram.org/bot"TOKEN"/getUpdates Write down the row of numbers coming after "id". This is our "Telegram_id" and will be needed in the next step.

3- Create the Script

sudo mkdir /etc/pam.scripts

Save this script in or other place /etc/pam.scripts/login-notification.sh

#!/bin/bash

TOKEN="kkkkk:kkkkkkkkk-I" ID="id-yourchat" HOSTNAME=$(hostname -f) DATE="$(date +"%d.%b.%Y -- %H:%M")" MESSAGE="�Raspberry SSH User: $PAM_USER açao: $PAM_TYPE em $DATE no � $HOSTNAME IP: � ($PAM_RHOST) !" URL="https://api.telegram.org/bot$TOKEN/sendMessage" curl -s -X POST $URL -d chat_id=$ID -d text="$MESSAGE" -d parse_mode='HTML' 2>&1 /dev/null exit 0

Make the script executable this comand:

    sudo chmod +x /etc/pam.scripts/login-notification.sh

Edit file sudo or nano vi /etc/pam.d/sshd and add the following to the end:

# SSH Alert script
session required pam_exec.so /etc/pam.scripts/login-notification.sh

This will trigger the script every login and every logout and you will get notified by telegram about ssh logins.

├───📄 README.md
├───📄 image.png
└───📄 ssh-logo.png\

Credits:(https://github.com/marcogreiveldinger/videos/tree/main/ssh-login-alerts)

This repository is a personal backup, as I made some changes to the code I thought it would be better.
Credits are cited and maintained
Big hug. up

About

✅A simple script for notification SSH access, exits and entries to the Server✅

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published