Linux set default password expiry for all new users

Posted on in Categories CentOS, Debian Linux, Howto, Linux, RedHat/Fedora Linux, Security, Sys admin, Ubuntu Linux, User Management last updated November 29, 2007

Under Linux password related utilities and config file(s) comes from shadow password suite. The /etc/login.defs file defines the site-specific configuration for this suite. This file is a readable text file, each line of the file describing one configuration parameter. The lines consist of a configuration name and value, separated by whitespace.

You need to set default password expiry using /etc/login.defs file (password aging controls parameters):

  1. PASS_MAX_DAYS : Maximum number of days a password may be used. If the password is older than this, a password change will be forced.
  2. PASS_MIN_DAYS : Minimum number of days allowed between password changes. Any password changes attempted sooner than this will be rejected
  3. PASS_WARN_AGE : Number of days warning given before a password expires. A zero means warning is given only upon the day of expiration, a negative value means no warning is given. If not specified, no warning will be provided.

Open file /etc/login.defs using text editor:
# vi /etc/login.defs
Setup (sample) values as follows:

Close and save the file.

See also:

Please note that much of the functionality that used to be provided by the shadow password suite is now handled by PAM suite. Next time I will write about PAM configuration.

9 comment

  1. My aduitor has asked me to change the value for this following 3:
    PASS_MAX_DAYS 99999

    As i have only Root account on the machine and no other account are configured.
    Also, i always took the console of the server. It’s configured in UI.

    Thanks in Advance !!!


  2. Hi,

    My question is the following:

    if you have those set in login.defs, can they be overridden by chage command?
    something like:

    chage -W10 -m7 -M42

    which will apply for this user? (/etc/login.defs or /etc/shadow – because chage modifies /etc/shadow in this example)


  3. @Zamfir: login.defs defines the defaults that are set up for a user on account creation. These defaults can be overridden by chage or passwd commands. To see what applies to a user, see
    chage -l $user

  4. I had this question asked on a non LDAP site. Guessing that this would even be difficult using LDAP and Kerebos.

    Can we remember password history for the last 14 logins (ie the user must not be able to use the same password again for at least 14 login attempts) and can we ensure a password complexity of at least 6 characters with a number. I.e. DonaldDaffyGoofeyBugsElmerCoyote9 ? ;)

  5. Can anyone help me how to edit this file through shell script. I would really appreciate if someone help me out t I am a newbie in linux scripting world.

Leave a Comment