Skip to content

Instantly share code, notes, and snippets.

@Caffe1neAdd1ct
Last active January 30, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Caffe1neAdd1ct/920a63cecb612962e4ce51f92e4e4709 to your computer and use it in GitHub Desktop.
Save Caffe1neAdd1ct/920a63cecb612962e4ce51f92e4e4709 to your computer and use it in GitHub Desktop.
Alerts on SSH Login
## Email Alert - make sure xmail is installed and replace email address below
echo 'ALERT - $HOSTNAME - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access at $HOSTNAME from `who | awk '{print $6}'`" you@email.here & disown > /dev/null 2>&1
## Register a webhook on slack "Incoming WebHooks" in the services section and replace hook url below
curl -X POST --silent --output /dev/null \
-H 'Content-type: application/json' \
-H "Accept: application/json" \
--data @<(cat <<EOF
{
"text": "ALERT - $HOSTNAME - $USER Shell Access on:' `date` `who`",
}
EOF
) \
https://hooks.slack.com/services/T000000/T0000000/MORECHARSHERE & disown > /dev/null 2>&1
## Both processes are put to the background to prevent hangs on ssh login and bash profile setup.
## Could prevent logins if the server is underload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment