WHM and Linux System User Password Expiration Synchronization
0 reputation · 24 Jan 2020, 04:43 UTC
0 reputation · 24 Jan 2020, 04:43 UTC
cPanel relies on the underlying Linux system user accounts for authentication. While WHM provides administrative tools to manage these accounts, there is a functional boundary between the cPanel interface and the system-level password aging policies defined in /etc/shadow.
When a system administrator implements a password expiration policy at the OS level to enforce security compliance, it is unclear how the cPanel login interface handles the transition when a password expires. Specifically, the behavior of the web-based authentication layer during the "grace period" or upon full expiration may differ from the standard SSH terminal experience.
Given a standard cPanel/WHM installation on a supported Linux distribution, what is the expected behavior when a system user's password expires according to the OS policy? Does the cPanel interface trigger a password change prompt, or does it simply deny access without providing a mechanism for the user to update their credentials via the web UI?
34275 reputation · 24 Jan 2020, 13:22 UTC
cPanel uses the underlying Linux account for authentication. When the system password reaches its expiration date (as defined in /etc/shadow), the pam_unix module will refuse login and prompt the user to change the password via the terminal or SSH.
By default, the web‑based cPanel login does not show a password‑change prompt when the underlying password has expired. The session is denied with an error similar to "Password has expired". This is because cPanel’s authentication layer does not automatically detect the expiration flag in /etc/shadow for web logins.
To give users a web UI path to update their password after an OS‑level expiration, you must either enable the WHM “Password Expiration” feature (which records an expiration date in the cPanel database) or implement a custom sync that updates /etc/shadow to match the WHM setting.
Below is a practical, safe approach to keep the two systems aligned:
Confirm that the WHM Password Expiration feature is enabled for the accounts you want to manage. If it’s disabled, the script will not apply any expiration.
Create a small PHP or shell script that iterates over all cPanel accounts, reads the expiration date via the UAPI, and applies it to the system user with chage:
#!/usr/bin/env bash
# sync_expiration.sh – one‑time sync of WHM to /etc/shadow
for user in $(uapi --output=json getacctlist | jq -r '.data[].user'); do
exp=$(uapi --output=json passwd | jq -r ".data."$user".expire_date")
if [[ "$exp" != "never" ]]; then
# Convert YYYY-MM-DD to epoch for chage
epoch=$(date -d "$exp" +%s)
chage -E $epoch $user
fi
done
Schedule a nightly cron job to keep the sync up to date:
0 2 * * * /usr/local/cpanel/bin/sync_expiration.sh >> /var/log/sync_expiration.log 2>&1
Verify the alignment:
chage -l username and confirm the “Password expires” field matches the date shown in WHM./etc/shadow with grep username /etc/shadow to see the EXPIRE field./var/log/cron or the log file you redirected to ensure the job ran successfully.To tailor the recommendation precisely, could you confirm whether the WHM Password Expiration feature is currently enabled for your accounts?
Use comments to ask for clarification. Post a solution as an answer.
34,275 reputation · 24 Jan 2020, 12:12 UTC
cPanel’s authentication layer simply forwards the login request to the system’s PAM stack. When /etc/shadow marks a password as expired, pam_unix returns the PAM_AUTHTOK_EXPIRED code. cPanel interprets that as a generic failure and displays the message
Your password has expired. Please contact your administrator.
The web UI does not invoke the PAM password‑change workflow that is available via SSH. Consequently, users cannot change the password directly from the login screen unless an additional module is enabled.
WHM’s Password Expiration feature stores an expiration date in the cPanel database. When that flag is set, cPanel shows a “Change Password” link after a successful authentication that bypasses the expired‑password check. Administrators can synchronize the two systems with a small script that copies the WHM expiration date to /etc/shadow (or vice‑versa).
Set a short expiry: sudo chage -E $(date -d '+1 day' +%s) alice
Attempt to log in to cPanel with user alice. You should see the “expired” message.
Reset the password via WHM or sudo passwd alice, then log in again. The login should succeed.
Note: If your environment uses custom PAM modules (e.g., LDAP, pam_pwquality) or if the account is locked by cPanel’s brute‑force protection, the message may differ. Always test in a staging environment before rolling out changes.