HowTo: NodeRed – Pushbullet notification at SSH login

From the FritzBox I am used to being notified as soon as someone logs on to my FritzBox. I think that’s a great security feature.

At some point I thought it would be nice if this feature were also available for the RaspberryPi. So I put together the solution below.

When a login is recognized on my NodeRed server (the RaspberryPi), it sends a message to me via Pushbullet.

In the article you will find everything you need to create your own NodeRed SSH login notification.


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/sicherheitshinweise/

Affiliate links / advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
So that you can install new nodes, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.

RaspberryPi – Setup for nerdiys!
RaspberryPi – The first configuration!

RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installation of NodeRed on the RaspberryPi
NodeRed – Installing new nodes
NodeRed – Import and export node code

Required tools:
-none-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in to the NodeRed configuration interface

Before you can edit your NodeRed configuration you must - if activated - first log in to the NodeRed configuration interface.

View of the login screen. Here you have to enter the login details that you entered during the configuration of the login. Information about this can be found in the article NodeRed - User Login Setup.

Import NodeCode

The NodeCode below contains everything necessary to evaluate a received notification and to forward it to you via Pushbullet. How you can add NodeCode to your NodeRed configuration is described in the article NodeRed – Importing and Exporting Node-Code.

So that the notification can be forwarded to you using Pushbullet, you must of course configure the Pushbullet Node accordingly. You can find tips on this in the article NodeRed – Sending Pushbullet Messages on Events

View of the configuration in the NodeRed configuration interface. you may have to configure the pushbullet node (here labeled “KlugesHaus”).

You can find the NodeCode under the following link:

https://github.com/Nerdiyde/NodeRedSnippets/blob/master/snippets/pushbullet_notification_at_ssh_login.json


Configure “Trigger”

So that your RaspberryPi also sends a “trigger” to NodeRed as soon as someone logs in, you now have to configure the following settings.

To do this, switch to the console of your RaspberryPi and open your .bashrc with the following command.

sudo nano /home/pi/.profile

If you are logged in with a different user name, you will of course have to adapt the command.

In the now opened file you have to use the arrow keys to …

… navigate to the end of the file.

Then insert the following code there.

#SSH login notification to nodeRed by Nerdiy.de
LOGIN_USER="$( whoami )"
LOGIN_DATE="$( date +%s )"
LOGIN_HOSTNAME="$( hostname)"

curl -Isk 'https://localhost:1880/ssh_login.json?user='$LOGIN_USER'&date='$LOGIN_DATE'&host='$LOGIN_HOSTNAME >> /dev/null

Then save the file by pressing CTRL + X and confirming with “Y” and “Enter”.

If you now log in to your RaspberryPi again via SSH, you should be notified by a Pushbullet message.

Of course you can also trigger other actions (e-mail, flashing lamp, etc.). Thanks to NodeRed, everything is freely configurable. 🙂


I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *