Skip to content

Setup email notifications when logging out and in via SSH. Emails are encrypted via GPG

Notifications You must be signed in to change notification settings

vanderblugen/SSH-Email-Notifications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 

Repository files navigation

SSH-Email-Notifications

This is a way to get email notifications when logging in and out via SSH on a Linux based system.
Email notificaitons are sent via mail that are gpg encrypted.

This has been tested on a RaspberryPi and an Ubuntu system.

Download the Script

wget https://raw.githubusercontent.com/vanderblugen/SSH-Email-Notifications/main/notify-ssh-login.sh

Modify the Email Address in the Script

nano notify-ssh-login.sh

Change recipient_email@address to the appropriate email address.

If GPG is not installed/configured Do This

Replace

cat $THISFILENAME | gpg -ear "recipient_email@address" | mail -a "Subject: Alert - Remote SSH $LOGWHAT notification" -a "X-Custom-Header: yes" "recipient_email@address.com"

With

cat $THISFILENAME | mail -a "Subject: Alert - Remote SSH $LOGWHAT notification" -a "X-Custom-Header: yes" "recipient_email@address.com"

Press <Ctrl+X> and then <Enter> when finished to exit

Setup permissions for the Script and Put It In Place

sudo chown root:root notify-ssh-login.sh
sudo chmod a=rx notify-ssh-login.sh
sudo mv notify-ssh-login.sh /etc

Edit SSHD file to Trigger Emailing

sudo nano /etc/pam.d/sshd

Add in the following lines to the end of the file

# Notify on successful log in / log out.
session optional pam_exec.so /etc/notify-ssh-login.sh

Press <Ctrl+X> and then <Enter> when finished to exit

All Set

Log out of the system and back in to verify functionality.

An email should be sent after logging in and out of the system via SSH now.

About

Setup email notifications when logging out and in via SSH. Emails are encrypted via GPG

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages