SSH Telegram Notification
First we have to write to the “BotFather” in Telegram, because we have to create a bot.
Simply send the following command and then follow the process:
|
|
You will then receive your API token. Please treat it like a password and save it in the PWS.
Now create a new group in Telegram and add the bot you have just created.
Then open Telegram in the browser of your choice and select the group you have created. You will then see the group ID in the address bar at the top. Everything after the # symbol belongs to the ID. The “-” symbol belongs to the ID!
In my case, the group ID is “-4250408318”, for example.
We will now create a new folder on our Linux server:
|
|
Now we create a file with the name “login-notification.sh” in the newly created folder:
|
|
We now insert the following code there:
|
|
Then save the file with CTRL + O + Enter and close it with CTRL + X.
As it is a script, we still need to make it executable:
|
|
Now let’s edit the PAM config for SSHD:
|
|
We insert the following line at the bottom:
|
|
Save the file again with CTRL + O + Enter and then close with CTRL + X.
You will now receive a notification in the Telegram group every time you successfully log in and log out.