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 ec2-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 can inject new credentials into your instance using this documentation.
After regaining SSH access, you can run this command to remove the password expiration error message (Make sure to replace ec2-user
with the name of your own user):
sudo chage --lastday 2024-10-11 ec2-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 ec2-user
To verify the password expiration has been disabled, you can list the details for your user:
sudo chage -l ec2-user