server-toolset
ssh-notify
Get notified through emails or Telegram messages when a user logs in to your server. Uses PAM modules, and a single Bash script!
Why use this?
- It's plug-and-play: use emails with or Telegram, or both.
- Distro agnostic: uses PAM and Bash with the least amount of surface.
Installation
Run install.sh to automate the steps below.
1. The script
cp ssh-notify.sh /usr/local/sbin/ssh-notify.sh
chmod 700 /usr/local/sbin/ssh-notify.sh
2. Configuration
mkdir /etc/ssh-notify
cp example.conf /etc/ssh-notify/config.conf
vim /etc/ssh-notify/config.conf # edit in place
chmod 600 /etc/ssh-notify/config.conf
3. PAM configuration
vim /etc/pam.d/sshd # edit in place and add the following lines:
# Send notification upon successful login (added by ssh-notify install.sh)
session optional pam_exec.so seteuid /usr/local/sbin/ssh-notify.sh
4. Logging
Optional, but suggested:
cp ssh-notify.logrotate /etc/logrotate.d/ssh-notify
The ssh-notify.logrotate tells logrotate to rotate /var/log/ssh‑notify.log once a day, keep seven old copies, compress older archives (but delay compressing the newest one), skip rotation if the file is empty or missing, and after each rotation immediately create a fresh log with permissions 600 owned by root:root; the sharedscripts directive ensures any postrotate commands (none are defined here) would only run once even if multiple files were listed.
Credits
Feel free to contact me for collaboration on anything!
Yiğid BALABAN, <fyb@fybx.dev>
My Website • X • LinkedIn
2024