Manchmal möchte man darüber informiert werden, wenn sich jemand per SSH auf einem Server anmeldet. Das kann man ganz einfach mit einem Shellskript und einer Erweiterung des PAM-Moduls erreichen.
ntfy-ssh-login.sh:
#!/bin/bash
PRIO=high
TAGS=warning
NTFY_URL=ntfy.example.com
CHANNEL=alerts
if [ "${PAM_TYPE}" = "open_session" ]; then
curl \
-H prio:"${PRIO}" \
-H tags:"${TAGS}" \
-d "SSH login: ${PAM_USER}@${HOSTNAME} from ${PAM_RHOST}" \
"${NTFY_URL}/${CHANNEL}"
fi
pam.d/sshd:
#%PAM-1.0
auth include system-remote-login
account include system-remote-login
password include system-remote-login
session include system-remote-login
session optional pam_exec.so <PATH-TO-ntfy-ssh-login.sh>