How to use pushbullet from the Linux Terminal!!

Linux/Linux Tutorials

Ever want to send push notification from your VPS or computer to your phone?

Well, this thing called pushbullet allows you to do just that. The best part is you don’t even have to make an account with them, you can log in with Google or Facebook!! I use this trick for two factor authentication on my VPS, so even if someone cracks the RSA key, they need a one time use PIN code.

Server Setup

All you need to do is use a tool called pip, which on Debian/Ubuntu, you can install with

 sudo apt install python-pip

then, simply install the pushbullet tool with:

 sudo pip install pushbullet-client

and you’re good to go!

Next, you need to get your access key, which can be done under settings>account, and scroll down till you reach a button called create access key. Then, copy it, and run:

 sudo pb set-key (key goes here)

The downside is that you need to use sudo or else you’ll need to enter the API key again.

Other device set up

To set it up on more or less any device in existence, all you need to do is to install the app/plugin if you’re on a browser, and login with the same Google/Facebook account. Then, you’ll receive push notifications with whatever you want to send.

Simple two factor auth

Here’s a little script that I put in /etc/profile to run on each login:

#!/bin/bash
email=""
trap 'echo got SIGINT' SIGINT
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
if [ "$ip" = "yourhomeip" ]
then
        logger -t ssh-wrapper $USER login from $ip
        echo "Home" | figlet
        exit
fi
hash=$((1000 + RANDOM % 9999))
#echo "Code: $hash" | mail -s "Auth code" -a "From: Auth <auth@gateblogs.com>" $email
echo "Auth code: $hash" | sudo pb push
read -p "PIN: " backupCode
backupCode2=$(echo $backupCode"abc")
backupCode2=$(echo "$backupCode2" | openssl dgst -SHA512 | sed 's/^.* //')
hash2="thisshouldbereplacedwithahashthatissalted"
if [ "$backupCode" != "$hash" ] && [ "$backupCode2" != "$hash2" ]
then
        iplookup=$(/usr/bin/iplookup $ip silent)
        printf "Admin,\nUser $USER just tried to log in(incorrect PIN) to your VPS from $ip\nIP info:\n\n$iplookup\n\nRegards,\nYour VPS" | mail -s "Incorrect PIN from $ip" $email
        echo "Wrong PIN!"
        kill -9 $(ps -ft $(tty) | awk '{print $2}' | sed -e "s/PID//g" | sed -e ':a;N;$!ba;s/\n/ /g')
else
        logger -t ssh-wrapper $USER login from $ip
        iplookup=$(/usr/bin/iplookup $ip silent)
        printf "Admin,\nUser $USER just logged in to your VPS from $ip\nIP info:\n\n$iplookup\n\nRegards,\nYour VPS" | mail -s "Login from $ip" $email
        echo "$USER logged in from $ip" | sudo pb push
        echo "NerdOfLinux" | figlet
        exit
fi
trap SIGINT

Leave a Reply