This script connects to an LDAP (LDAPS) directory and notifies users via email when their password is about to expire.
- Secure LDAPS connection
- Password expiry calculation
- Email notifications with customizable thresholds
- JSON-based config
- Integrated with
systemd+systemd.timer
- Ubuntu Server 20.04+
- Python 3
- Packages:
ldap3,pytz
sudo apt install python3 python3-pip
pip3 install ldap3 pytz- Create
/etc/password_notify/config.jsonbased on the template:
cp config.example.json /etc/password_notify/config.jsonEdit config.json and set:
ldap_server,ldap_user,ldap_passwordbase_dn,email_server,email_senderldap_ca_cert(or system default)
Run manually:
sudo /usr/local/bin/password_notify.pyView logs:
tail -n 50 /var/log/password_notify/password_notify.log[Unit]
Description=Password Expiry Notification Service
After=network.target
[Service]
ExecStart=/usr/local/bin/password_notify.py
User=root
Type=simple
[Install]
WantedBy=multi-user.target[Unit]
Description=Runs password_notify every hour
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.targetEnable timer:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable --now password_notify.timer/usr/local/bin/password_notify.py— main script/etc/password_notify/config.json— configuration file/var/log/password_notify/— logs and state
- NEVER commit
config.jsonto public repos. - Use
.gitignoreto exclude secrets.
MIT License — you are free to use, modify, and distribute.