https://github.com/alirezaopmc/ssh-notifier
A Telegram Notifier for ssh loggins
https://github.com/alirezaopmc/ssh-notifier
bash linux
Last synced: about 2 months ago
JSON representation
A Telegram Notifier for ssh loggins
- Host: GitHub
- URL: https://github.com/alirezaopmc/ssh-notifier
- Owner: alirezaopmc
- Created: 2023-11-23T22:36:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-24T21:41:50.000Z (over 2 years ago)
- Last Synced: 2023-11-24T23:31:06.175Z (over 2 years ago)
- Topics: bash, linux
- Language: Shell
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Telegram SSH Notifier

# Overview
This is a simple Telegram SSH notifier script written in Bash. It sends notifications to a specified Telegram chat whenever an SSH session is initiated on the server.
# Installation
## Step 1: Copy the Directory
Copy the ssh-notifier directory to the /usr/local/ directory to make it accessible publicly.
```bash
cp -r ssh-notifier /usr/local/
```
## Step 2: Update PAM Configuration
Open the /etc/pam.d/sshd file and add the following line at the end. This line invokes the notifier script with relevant parameters.
```bash
session required pam_exec.so /usr/local/ssh-notifier/app.sh "$PAM_USER" "$PAM_RHOST"
```
## Step 3: Restart SSH Service
Restart the SSH service to apply the changes.
```bash
service ssh restart
```
# Configuration
Prior to utilizing the notifier, ensure that you create a .env file containing the necessary variables:
```bash
TELEGRAM_BOT_TOKEN="YOUR_BOT_TOKEN"
TELEGRAM_CHAT_ID="YOUR_CHAT_ID"
```
Replace YOUR_BOT_TOKEN and YOUR_CHAT_ID with your actual Telegram bot token and chat ID.
# Usage
Once configured, the notifier will send a Telegram message whenever a user logs into the server via SSH.
# Additional Notes
Ensure that the necessary permissions are set for the script and that it is executable. You can use the following command:
```bash
chmod +x /usr/local/ssh-notifier/app.sh
```
Feel free to customize the script further to suit your needs.