Created
June 15, 2022 13:55
-
-
Save nulconaux/362495609bd8fe655b154f0905d5bd49 to your computer and use it in GitHub Desktop.
Notify whenever someone logs in via SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://cmaster11.medium.com/how-to-get-notified-whenever-someone-logs-in-via-ssh-947a8f8d4f37 | |
# Edit the /etc/pam.d/sshd file and append the following line at the end: | |
# session [default=ignore] pam_exec.so /bin/bash /opt/notify-ssh.sh | |
# We want to trigger the script only when the SSH session starts. | |
# To be notified also when session closes, you can watch for | |
# the "close_session" value. | |
if [[ "$PAM_TYPE" != "open_session" ]]; then | |
exit 0 | |
fi | |
read -r -d '' CONTENT <<-EOF || true | |
Now UTC: $(date --utc "+%F %T") | |
Env: | |
$(printenv) | |
EOF | |
curl -X POST --data-urlencode \ | |
'payload={"channel": "#channel", "text": "SSH: User logged in"}' \ | |
https://hooks.slack.com/services/// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment