Score:1

Cant send mail when ssh login succesfull through pam_exec

hk flag

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?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.