Ntfy is a simple notification service that allows sending notifications via a simple HTTP request.
Sending notifications is done by making a request to a unique URL that represents a topical namespace. Here’s a simple example from the ntfy.sh homepage:
The ntfy.sh website mentions that the topic name is essentially a password, so it’s important to pick a name that’s not easily guessed.
I usually use a short name (e.g.
notifications) followed by a unique
UUIDv4 string, which results in a topic name that looks like this:
Since the app will truncate the string, the extra length that’s appended doesn’t affect readability in the least.
To enable notifications for SSH logins, the system-wide profile will need to be edited:
And the following snippet added to the end of the file:
notifications-8b8d0ca2-3e9d-444a-8169-480042125f6a is the Ntfy topic.
I found the
awklogic from a blog post on email alerts for SSH logins, which I repurposed for use with Ntfy.
One additional change I made from the original code snippet was sending the output to
/dev/null which prevents users from seeing the verbose output when they themselves login.
Below is an example of how a login notification looks in the Ntfy app:
This type of system requires less moving parts than using
sendmail for example, and push notifications are practically instant.
- ntfy - ntfy.sh