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.
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/
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. 🙂
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
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.
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
You can find the NodeCode under the following link:
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. 🙂
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. 🙂