https://github.com/devvyyxyz/logging-ssh-to-discord
https://github.com/devvyyxyz/logging-ssh-to-discord
bash discord discord-bot logging ssh
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/devvyyxyz/logging-ssh-to-discord
- Owner: devvyyxyz
- License: mit
- Created: 2024-06-11T00:25:48.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-11T00:32:41.000Z (about 2 years ago)
- Last Synced: 2025-02-09T15:44:21.286Z (over 1 year ago)
- Topics: bash, discord, discord-bot, logging, ssh
- Language: Shell
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logging SSH to discord





This script enhances the functionality of Alexander Henderson's original script for logging SSH sessions to Discord. The original script and blog post can be found [here](https://blog.alexsguardian.net/posts/2022/07/02/LoggingSSHtoDiscord/), and credit goes to Alexander Henderson ([alexandzors](https://github.com/alexandzors)).
## Overview
This Bash script is designed to be added to `/sbin/` and made executable. It integrates with the SSH PAM (Pluggable Authentication Modules) to log SSH session events, such as login and logout, to a Discord channel through a webhook.
## Preview

## Installation
1. **Copy the Script:**
- Copy the script to `/sbin/` and make it executable:
```bash
sudo touch /sbin/sshd-login
sudo chmod +x /sbin/sshd-discord-login.shsudo chmod +x /sbin/sshd-login
sudo chown root:root /sbin/sshd-login
sudo nano /sbin/sshd-login
```
2. **Edit PAM Configuration:**
- Open `/etc/pam.d/sshd` in a text editor.
- Add the following line to the bottom of the file:
```plaintext
session optional pam_exec.so /sbin/sshd-discord-login.sh
```
3. **Set Permissions for Logging:**
- Ensure the log file has the correct permissions:
```bash
sudo touch /var/log/seen_ips.log
sudo chmod +x /var/log/seen_ips.log
sudo chown root:root /var/log/seen_ips.log
```
4. **Set Configuration Variables:**
- Edit the script and set the `WEBHOOK_URL`, `DISCORDUSER`, and `URGENT_ROLE` variables to appropriate values.
5. **Restart SSH Service:**
- Restart the SSH service for changes to take effect:
```bash
sudo service sshd restart
```
## Usage
Once installed, the script will send messages to the configured Discord channel when users log in or out via SSH. It differentiates between new and known remote hosts, providing additional context.
## Credits
- Original script by Alexander Henderson ([alexandzors](https://github.com/alexandzors)): [LoggingSSHtoDiscord](https://blog.alexsguardian.net/posts/2022/07/02/LoggingSSHtoDiscord/)
## Disclaimer
This script is provided as-is without any warranty. Use it at your own risk, and ensure that you comply with your organization's policies and guidelines.
## License
This project is licensed under the MIT - see the [LICENSE](LICENSE) file for details.
## Deployment
### Replit
[Deploy to Replit](https://replit.com/import/github/devvyyxyz/logging-ssh-to-discord)