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 azureuser.
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 reset your credentials or create a new Linux user via the Reset password tool in the Azure portal.
After regaining SSH access, you can run this command to remove the password expiration error message (Make sure to replace azureuser
with the name of your own user):
sudo chage --lastday 2023-10-16 azureuser
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 azureuser
To verify the password expiration has been disabled, you can list the details for your user:
sudo chage -l azureuser