Linux set default password expiry for all new users

by on April 30, 2006 · 8 comments· LAST UPDATED November 29, 2007

in , ,

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:
PASS_MAX_DAYS 30
PASS_MIN_DAYS 1
PASS_WARN_AGE 7

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.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 8 comments… read them below or add one }

1 John September 13, 2006 at 7:12 pm

Is this for email passwords or system logins like cPanel or SSH?

Thanks

Reply

2 nixcraft September 13, 2006 at 8:48 pm

John,

This is for system password aka ssh login, if your email server using system password then same limit will apply

HTH

Reply

3 MrKIPS August 20, 2009 at 11:08 pm

Thank you. I came across this article while searching for information on password expiry. Useful.

Reply

4 easwaramoorthi September 21, 2010 at 6:04 am

Thanks you
Its very good,

Reply

5 does this apply for Root account ? October 8, 2010 at 12:06 pm

My aduitor has asked me to change the value for this following 3:
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_WARN_AGE 7

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 !!!


Cheer’s
-Mayank

Reply

6 Zamfir May 26, 2011 at 11:56 am

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)

br
zamfir

Reply

7 Olly June 5, 2011 at 3:43 pm

@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

Reply

8 colin October 29, 2012 at 4:17 am

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 ? ;)

Reply

Leave a Comment

Tagged as: , , , , , , , ,

Previous post:

Next post: