Bash script that notifies a user through Discord when a new SSH connection is established on a machine. It sends a message containing details about the connection, including the username, IP address, location, time, and hostname.
To get the script up and running, follow these steps:
Ensure that curl is installed on your machine. You can install it using the package manager for your operating system:
# For Arch based systems
sudo pacman -S curl
# For Debian/Ubuntu-based systems
sudo apt-get install curl
# For Red Hat/CentOS-based systems
sudo yum install curlEdit the script to replace the placeholder URL with your actual Discord channel webhook URL.
WEBHOOK_URL="https://discord.com/api/webhooks/1234567890/ABCDEFGHIJKLMN1234567890"Copy the script to the /etc/profile.d directory to ensure it runs on every user login.
sudo cp ssh-discord-notifier.sh /etc/profile.d/ssh-discord-notifier.sh
sudo chmod +x /etc/profile.d/ssh-discord-notifier.sh- Get location using IP address: The script uses
ip-api.comto retrieve the city, region, and country based on the IP address of the SSH client. - Send a message to Discord: A Discord message is formatted with the user details and sent to the specified webhook URL using
curl. - Run on SSH connection: The script checks if an SSH connection is present and triggers the notification process.
- Runs in the background: The script operates in the background, ensuring there is no delay or interruption to the user's session while it completes its tasks.