How to set user password to never expire in Linux/Ubuntu/Docker

Linux, Ubuntu, and Linux-based Docker images, the password expiry can be set by using the change command.

chage - change user password expiry information

Let us explore it in detail.

Viewing the user password expiry details.

To view the current password expiry date, use the -l option

chage -l <USERNAME>

Example:

[email protected]:~# chage -l codex
Last password change					: Sep 28, 2020
Password expires					: Oct 08, 2020
Password inactive					: never
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 10
Number of days of warning before password expires	: 7

The option to set the user password to never expire

To make the user password never expire, set the MAX_DAYS to -1 (minus one)

chage -M -1 <USERNAME>

Example:

chage -M -1 codex

Let us verify the change:

[email protected]:~# chage -l codex
Last password change					: Sep 28, 2020
Password expires					: never
Password inactive					: never
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: -1
Number of days of warning before password expires	: 7

Here is the complete list of options available:

Usage: chage [options] LOGIN

Options:
  -d, --lastday LAST_DAY        set date of last password change to LAST_DAY
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -h, --help                    display this help message and exit
  -i, --iso8601                 use YYYY-MM-DD when printing dates
  -I, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --list                    show account aging information
  -m, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -M, --maxdays MAX_DAYS        set maximum number of days before password
                                change to MAX_DAYS
  -R, --root CHROOT_DIR         directory to chroot into
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS

Reference: Ubuntu – change command man page

Note: This is tested on Ubuntu Linux, the same should work across most Linux distributions and Linux-based containers.