Linux User Password Expiration
Overview
When logging in with a Linux user via SSH, you may get this error:
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for admin-user.
Current password:
This can be an issue if you've never set a password for your Linux user, as you'll be prompted to reset your password regardless if you've created one or not.
Cause of the password expiration
You will receive this error message due to a password policy in the /etc/login.defs
file, which requires you to reset your password every 365 days.
# Password aging controls:
#
# PASS_MAX_DAYS Maximum number of days a password may be used.
#
PASS_MAX_DAYS 365
Resolving the issue
To regain SSH access into the VM, you may need to add a new SSH key onto the VM. Check out the How to SSH into SFTP Gateway article for how to manually add an SSH key to your VM.
After regaining SSH access, you can run this command to remove the password expiration error message (Make sure to replace admin-user
with the name of your own user):
sudo chage --lastday 2023-10-16 admin-user
Set the time of the command to the current date and it will act as if this user's password has been reset today, so their password technically isn't expired anymore and they won't be prompted to change it.
Then, run this command to change the expiration date to never, so the password will never expire:
sudo chage -M -1 admin-user