How to Monitor All SSH Connections Through Discord? 🌍🎥

This is a tutorial to setup notification of each ssh connection to your server directly on discord ! 🫧

How to Monitor All SSH Connections Through Discord? 🌍🎥

How to Monitor All SSH Connections Through Discord? 🚀🌟

Imagine having a digital watchdog that keeps an eye on SSH connections to your server, alerting you on Discord every time someone logs in. Sounds cool, right? Let’s set this up and add an extra layer of awareness to your server's security !

🕵️ Step 1: Summon Your Discord Webhook

Before we unleash the magic, we need to create a Discord webhook. Think of it as recruiting a digital messenger.

Enlist Your Messenger

  1. Dive into Discord: Choose your preferred updates channel, and hit Edit channel > Integrations.
  2. Webhook Initiation: New to webhooks? Click Create Webhook. If you're a veteran, select View Webhooks then New Webhook.
  3. Craft an Identity: Give your webhook a catchy name and an avatar.
  4. Secure the Communications: Copy the WEBHOOK URL; it’s the key to your direct line.
  5. Save the Day: Make sure to hit Save.

Pasted image 20240310013126.png

Pasted image 20240310013304.png

🚀 Step 2: Dive into Your Server

Gear up for some command-line action. SSH into your server to start setting up our digital watchdog.

🌟 Step 3: The Spellbook - Create a Script

Now, we're crafting a spell in the form of a script named ssh-check.sh.

The Incantation

bash
#!/bin/bash

# Your secret communication line
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/XXXXXXXXXX/XXXXXXXXXXXXXXXX"

# Detect the intruder... I mean, the guest
IP=$(echo $SSH_CLIENT | awk '{print $1}')
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"SSH connection from IP: $IP\"}" "$DISCORD_WEBHOOK_URL"

Unlock the Code: Swap in your unique webhook URL here.

This enchantment alerts you with the IP address of every connecting soul.

⭐ Step 4: Awaken the Spell

Give life to your script, making it a vigilant guardian:

bash
sudo chmod +x ./ssh-check.sh

🎥 Step 5: The Guardian's Post - Modify SSH Config

Let’s ensure our guardian watches over every entrance:

bash
vim /etc/ssh/sshd_config

📝 Feel free to use your favorite text editor. If vim feels like ancient runes, try nano.

Whisper this at the file’s end:

bash
ForceCommand /path/to/ssh-check.sh && /bin/bash

⚠️ WARINING ! If you dont have bash, setup correctly the path to your shell, otherwise you will not be able to connect to your shell with ssh

❤️ Step 6: Awaken the Guardian

Revive the SSH service to embrace the new guardian:

shell
systemctl restart sshd

🚪 I advise you to NOT close your current connection right now ! Try to connect to your server with another terminal first to ensure everything work.

🌍 Step 7: Revel in Your Fortress

Congratulations! You’ve transformed your server into a digital fortress, with alerts for every SSH connection sent straight to your Discord. Your server is not just secured; it’s connected.

Pasted image 20240310023334.png


● brev.al / blog

  1. Auth is a Dumpster Fire. Can 'Better Auth' Put It Out?

    A critical look at the painful state of web authentication. We dive into the failures of Auth.js, the hidden traps of Supabase, and whether the new challenger, Better Auth, is the hero we've been waiting for.

    #Server#Front#Workflow#Database7 min read

    Auth is a Dumpster Fire. Can 'Better Auth' Put It Out?
  2. They Said It Would Burn: Tales from the Trenches of PC Enthusiasm

    A deep dive into the world of PC enthusiasm, where online theory clashes with real-world results. From underdog motherboards powering beastly CPUs to the surprising state of GPU virtualization, this is a guide for those who dare to experiment.

    #Experiment#Linux#Server#ART6 min read

    They Said It Would Burn: Tales from the Trenches of PC Enthusiasm
  3. Your Own Personal Jarvis (or maybe just a Smart Teacup): Building a Local, Private LLM

    A guide for non-developers on setting up private, local Large Language Models using tools like Ollama and Open WebUI, covering hardware, privacy, scaling, and pitfalls, inspired by a lawyer's journey.

    #AI#Server#Linux#Workflow#Database10 min read

    Your Own Personal Jarvis (or maybe just a Smart Teacup): Building a Local, Private LLM
  4. Mastering State and Data Synchronization in Modern React Applications

    Explore common challenges in syncing frontend state with backend data in React and learn about various strategies, from simple refetching to advanced sync engines and modern architectural patterns.

    #Front#Database#News#Experiment#Server7 min read

    Mastering State and Data Synchronization in Modern React Applications

Another way of looking at things.