Turning off password expiration on Linux

10,907
$ man 5 shadow

describes the format of that file. Quoting from there, the fifth field is the maximum password age.

maximum password age The maximum password age is the number of days after which the user will have to change her password.

After this number of days is elapsed, the password may still be valid. The user should be asked to change her password the next time she will log in.

An empty field means that there are no maximum password age, no password warning period, and no password inactivity period (see below).

If the maximum password age is lower than the minimum password age, the user cannot change her password.

In your case, you've already hit the trigger, so you also need to get rid of the prompt to immediately change the password on the next login. Again consulting the man page...

date of last password change The date of the last password change, expressed as the number of days since Jan 1, 1970.

The value 0 has a special meaning, which is that the user should change her password the next time she will log in the system.

An empty field means that password aging features are disabled.

So you should also delete the zero from the third field. And once you've disabled that, there's no need for the fourth one either.

So you should be able to delete the fifth field entirely to achieve what you want. As in

root:$6$U.dnAQ2f$FV$/aF23Yn.sq1BYVjinlI9251nAarzqGKES18RxadV5bTakcfCNYAMljUwSaQZYV0r4MttHF0SFO7ebq3E1m/:::::::

That said, I would generally advise against directly editing files like this unless you're 100% sure you know what you're doing.

Edit: Also, it appears that chage is part of the passwd package on Ubuntu, which I would have assumed you already had installed.

Share:
10,907

Related videos on Youtube

sven
Author by

sven

Updated on September 18, 2022

Comments

  • sven
    sven over 1 year

    I see a lot documents suggesting to use chage on Debian and Ubuntu, but apt-get update && apt-get install chage does not install the package. For example,

    root@ubuntu:~/Desktop# apt-get install chage
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package chage
    

    I found that I need to edit /etc/shadow. How exactly do I need to edit the root line below, so that my Linux does not ask me to change the password on the each log in?

    root@ubuntu:~# cat /etc/shadow
    root:$6$U.dnAQ2f$FV$/aF23Yn.sq1BYVjinlI9251nAarzqGKES18RxadV5bTakcfCNYAMljUwSaQZYV0r4MttHF0SFO7ebq3E1m/:0:0:99999:7:::
    

    I edited the root line as deong suggested

    root:$6$U.dnAQ2f$FV$/aF23Yn.sq1BYVjinlI9251nAarzqGKES18RxadV5bTakcfCNYAMljUwSaQZYV0r4MttHF0SFO7ebq3E1m/:0:0:::::
    

    It stills asks for a password on log in.

    I also followed the instructions on http://www.lifelinux.com/setting-up-password-aging-in-linux/:

    root@ubuntu:/home# chage -m 7 -M 60 -W 7 -I 7 root
    root@ubuntu:/home# chage -m 0 -M 99999 -I -1 root
    root@ubuntu:/home# change -l root
    -bash: change: command not found
    root@ubuntu:/home# chage -l root
    Last password change                                    : password must be changed
    Password expires                                        : password must be changed
    Password inactive                                       : password must be changed
    Account expires                                         : never
    Minimum number of days between password change          : 0
    Maximum number of days between password change          : 99999
    Number of days of warning before password expires       : 7
    

    What do I need to edit to remove password must be changed? I also did chage -I -1 -m 0 -M 99999 -E -1 root, but it did not help.

  • Admin
    Admin about 11 years
    I edited the line as you did but I still get ubuntu login: root Password: You are required to change your password immediately (root enforced) Changing password for root. (current) UNIX password: Enter new UNIX password: Retype new UNIX password:
  • Admin
    Admin about 11 years
    do you know if I need to edit another file as well to disable password expiration?
  • deong
    deong about 11 years
    Sorry...I didn't read closely enough. I've edited my answer to include a bit more. Note that all of this is clearly laid out in the man page.