Gotify实现SSH登录通知
1.安装 curl sudo apt update sudo apt install curl 2.创建 SSH 登录成功通知脚本 创建: sudo mkdir /usr/local/sbin/script sudo vim /usr/local/sbin/script/gotify-ssh-login.sh 写入: #!/bin/bash # 只处理 SSH session 建立 [ "$PAM_TYPE" = "open_session" ] || exit 0 GOTIFY_URL="https://gotify.example.com" GOTIFY_TOKEN="AbCdEf123456..." HOSTNAME=$(hostname) USER_NAME="${PAM_USER:-unknown}" REMOTE_IP="${PAM_RHOST:-unknown}" TIME=$(date '+%Y-%m-%d %H:%M:%S %Z') MESSAGE="服务器:${HOSTNAME} 用户:${USER_NAME} IP:${REMOTE_IP} 时间:${TIME}" curl -fsS \ --max-time 5 \ -H "X-Gotify-Key: ${GOTIFY_TOKEN}" \ -F "title=🔐 SSH Login" \ -F "message=${MESSAGE}" \ -F "priority=5" \ "${GOTIFY_URL}/message" \ >/dev/null 2>&1 exit 0 注意修改: GOTIFY_URL GOTIFY_TOKEN 修改权限: sudo chmod 700 /usr/local/sbin/script/gotify-ssh-login.sh 3.让 SSH 登录时执行脚本 编辑: ...