1

Noob ubuntu user here, I want to send an email on succesfull ssh login on my Ubuntu 20.04.5 LTS machine, I got the idea from this other thread:

How do I set up an email alert when a ssh login is successful?

I edited /etc/pam.d/sshd file and added the last line

/etc/pam.d/sshd

session    optional     pam_keyinit.so force revoke
session optional pam_exec.so seteuid /usr/local/bin/sendmail.sh

And my sendmail script (changed key and mail for privacy reasons):

/usr/local/bin/sendmail.sh

#!/bin/bash
##This script sends a message

if [ "$PAM_TYPE" != "close_session" ]; then host="'ubuntu-server'" subject="SSH Login: $PAM_USER from $PAM_RHOST on $host" curl -s --user 'api:key-xxxxxxxxxxxxxxxxxxxxxxxx' https://api.eu.mailgun.net/v3/mydomain.com/messages -F from='Server Notification <postmaster@mydomain.com>' -F to='mymail@gmail.com' -F subject="$subject" -F text='Detected succesfull SSH login' fi

exit 0;

Is there something I missed? do I have to restart pam or something?

Where can I see error logs if they exist?

0 Answers0