Skip to content

gianluca-mascolo/ssh-telegram-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

ssh-telegram-notifier

Small sshrc to notify logins to a telegram bot

Scope

This script allow you to get notified on telegram everytime someone login to a server via ssh

How it works

Every time an user login, /etc/ssh/sshrc is executed (see man ssh). This sshrc will curl a message to your custom bot with basic information about login.

Screenshot

sshnotify

Setup

  • Contact @BotFather and create a new bot.
  • Write down your token and use it in variable TELEGRAM_BOT_TOKEN
  • Open the bot you created and start conversation
  • Retrieve you chat id and use it in variable TELEGRAM_CHAT_ID
curl --silent "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/getUpdates" | jq .
  • modify sshrc with TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID
  • copy it to /etc/ssh
cp sshrc /etc/ssh/sshrc
chown root:root /etc/ssh/sshrc
chmod 0755 /etc/ssh/sshrc
  • if you are logged into server via ssh, leave the current shell open and test the script making a new login
  • enjoy!

Possible improvements

The sshrc can be read by every user on the system, exposing you telegram bot password. It will be better if one can have a separate daemon running by a private user that accept an incoming message from sshrc and write to your bot.

Thanks to

Follow me!

Do you like it? Follow me on telegram: http://t.me/linuxcheatsheet

Releases

No releases published

Packages

No packages published

Languages