I would like to be notified if there is ever a successful SSH login into the machine that I accept external connections on via NTFY. Since I frequently login this machine locally (192.168.1.0/24), I'd like to avoid notifications when the connection is from that range.
I am following the example listed here: https://docs.ntfy.sh/examples/#ssh-login-alerts
The notifications work correctly but I am trying to modify my script to exclude 192.168.*, my bash is awful and I have been banging my head against this for hours.
I have modified the ntfy-ssh-login.sh to this:
#!/bin/bash
if [ "${PAM_TYPE}" = "open_session" ]; then
if [ "${PAM_RHOST}" != 192.168.* ]; then
curl \
-H prio:high \
-H tags:warning \
-d "SSH login: ${PAM_USER} from ${PAM_RHOST}" \
http://192.168.1.137:8777/alerts
fi
fi
which I expect will not send the alert to NTFY if PAM_RHOST starts with 192.168. However, it always sends the alert. I know the value of PAM_RHOST starts with that value because its included in the alert:
30/08/2023, 22:12 Priority 4
⚠️ SSH login: --redacted-- from 192.168.1.11
That 192.168.1.11 is set by ${PAM_RHOST}.
I am sure I am doing something silly.
192.168.*to be treated as a pattern, I believe you would need to use[[for youriftest as[does not seem to support string patterns:if [[ "${PAM_RHOST}" != 192.168.* ]];