Makes use of the Pushover API to send native notications for both successful and failed login attempts to your SSH server.
Failed login script reference here
- Ensure that you have set your Pushover API and user keys at the top of each script before using
- You can sign up for a Pushover account here and register for a Pushover API key here
- These scripts can be placed in any folder, however I have decided on
/etc/ssh
for consistency and to place them among ssh config files. - Installing the script for failed login attempts is risky, as messing up a file may screw up your system. Be careful when editing PAM files in general. Backups are a good idea.
This script will notify you of a successful login
- Place script inside of
/etc/ssh
and allow script to be executable by running:
sudo chmod +x /etc/ssh/login-notify.sh
- Then run:
echo "session optional pam_exec.so seteuid /etc/ssh/login-notify.sh" | sudo tee -a /etc/pam.d/sshd
This will run the script on successful authentication into an ssh session.
- If everything was successful, upon your next successful login, you should recieve a Pushover notification!
This script will notify you of a failed login attempt
- Place script inside of
/etc/ssh
and allow script to be executable by running:
sudo chmod +x /etc/ssh/failed-login-notify.sh
- Edit the common-auth file by doing:
sudo nano /etc/pam.d/common-auth
You can replace nano with your preferred text editor. You can create a backup of your current common-auth file by doing sudo cp /etc/pam.d/common-auth /etc/pam.d/common-auth.bkup
. This is so you can revert to it in case something goes wrong.
- Find the line below:
auth [success=1 default=ignore] pam_unix.so nullok_secure
and change success=1
to success=2
. This is so that the script does not run if the login was successful. THIS IS IMPORTANT OR YOU WILL NOT BE ABLE TO LOGIN.
- Add this line directly below the line in step 3:
auth [default=ignore] pam_exec.so seteuid /etc/ssh/failed-login-notify.sh
- Save and close. You can test this script by attempting to SSH into the server and typing in an incorrect password. If you want to turn this behavior on for physical logins as well, simply remove the if condition in the script testing for whether
"$PAM_SERVICE" = "sshd"
. - If everything was successful, you should recieve a Pushover notification!