DEV Community

Discussion on: SSH Login Notifications in Slack

Collapse
 
boly38 profile image
Brice • Edited

This post is 2 years old, anyway I'm using your tip.

Here is my feedback:

  • the script may be little more simple for a conventional slack hook (one channel only):
#!/bin/bash
if [ "$PAM_TYPE" != "close_session" ]; then
        SLACK_WEBHOOK_ENDPOINT=https://hooks.slack.com/services/blah/blahblah/blahblahblah
        host="$(hostname)"
        user="${PAM_USER}"
        remoteip="${PAM_RHOST}"
        curl -X POST --data "{\"type\": \"mrkdwn\",\"text\": \"${remoteip} - SSH Login : ${user} connected to \`$host\`\"}" ${SLACK_WEBHOOK_ENDPOINT}
fi
exit
Enter fullscreen mode Exit fullscreen mode
  • the script may start with shebang (#!/bin/bash) in order to avoid exit code 8

thanks for this tips 👏