Linux Change Password

Linux Change Password Command: Change password expiry in Linux

Getting the Linux change password notification again? The one that tells you it’s about to expire? Here’s how to get it to stop bugging you.

Linux is one of the most popular operating systems for servers, and Linux also offers a great desktop OS. However, there are some things that can be difficult to understand when you’re new to Linux. One example is passwords expiry – what does this mean? How do you change the expiration date for your password in Linux? How do you change user password, UNIX password, and use the passwd command?

If you’re not in IT services, or sidebar not a techie, the Linux change password command and coding the expiry date can all seem overwhelming. If you can barely remember your username, setting expiration dates is the last thing on your mind. But, Linux change account passwords settings allow you to keep yours and others users in Linux secure. By using the root user and the user root password and the command line chage.

In this article, we’ll answer these questions and more. Keep reading to learn more.

Change expiry and enter new UNIX password in Linux

change user password linux

“chage” is the command to list & change the user password aging information for the change password user account. Use the passwd command chage to change the number of days between user password expiry and the current date. It’s easy to access the chage command line to utilize it in Linux. Think of it as the account password change button in the shadow file.

The change the password notification will be sent and passwords will be set to expire on the date you specify. The valid range is from 0 (today) up until 90 years in future, and if it’s less than today then a warning message pops-up again reminding that the change user password in Linux has already expired.

Here’s a real quick rundown on how to show the expiration date of a particular linux user account. Here are the different settings:

  • Listing password aging for user and user accounts
  • Change the number of days to expire for the alert to change user password on the account
  • Change the password to never expire so you have control and can change your own password
  • Change account expiry to a specific date to change the password

Let’s explore how to use this command in the terminal!

Listing password aging for user

linux user password change

chage command with option -l shows the expiry details of a specific user. This sudo command allows users to plan on a new password the next time the user’s password is set to expire.

In this example, the user’s last new password change was on Dec 25th 2017 and it expires in 90 days. The user will be notified within login 7 days before expiry.

 [root@centos01 ~]# chage -l demouser
 Last password change : Dec 25, 2017
 Password expires : never
 Password inactive : never
 Account expires : never
 Minimum number of days between password change : 0
 Maximum number of days between password change : 90
 Number of days of warning before password expires : 7
 [root@centos01 ~]#

Change the number of days to expire

change password for user linux

Use -M option and provide the number of days to expiry. You can see in the example below, the user can change to their new password the next time it’s required, in 180 days.

Some of the reasons you might want to change the number of days to expiry are to enforce a more stringent new password policy, to force the user into changing their passwords on time, to take over the account with the sysadmin, doubling back to the root user, etc.

[root@centos01 ~]# chage -M 120 demouser
 [root@centos01 ~]# chage -l demouser
 Last password change : Jan 25, 2018
 Password expires : May 25, 2018
 Password inactive : never
 Account expires : never
 Minimum number of days between password change : 0
 Maximum number of days between password change : 120
 Number of days of warning before password expires : 7
 [root@centos01 ~]#

Change the password to never expire

how to change password in linux

You can use chage to make the user’s password never expire with the below options. This sets the user password/UNIX password to never expire. Some reasons why you may want to switch to the password never expiring are if you’re sharing the account with a co-worker or if it is for your personal use.

This way neither one of you will be left in the lurch if you forget your password. You simply manage the root access passwd and type passwd command to change it yourself when needed.

You can also set the number of days to change and how many warnings you want before it expires with chage. Be careful to keep track of your passwords and to set the correct number of days for your user password.

This command will create an expiration date that is in never part, so it won’t expire at all: PASSWORD_MAXAGE=never chage -M 0 username . A maximum password age can be specified as a time span with units such (years) or (-m):

Option one: -M199200 — this will set the Linux password to never expire and then change user password expires attribute from “never” (default)to NEVER (-1201). The screen looks like this.

 [root@centos01 ~]# chage -m 0 -M 99999 -I -1 -E -1 demouser
 [root@centos01 ~]# chage -l demouser
 Last password change : Jan 25, 2018
 Password expires : never
 Password inactive : never
 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
 [root@centos01 ~]#

Change account expiry to specific date

change linux password

You can set the user password commands or UNIX password and the entire account distribution to expire on a specific date or +N number of days from the current date.

Some of the reasons this is helpful are when you are testing a potential new employee and whether the information they gave is accurate, and want the user password to expire after the test window is done. When the file is set to expire, or when an employee is terminated, etc shadow.

All of this is done with one command: ot@centos01 ~] #chage -E +21 demouser (type in your password and answer y)[/size][/li][line break=true

To set an expiration date, use: chage username +N days from now.

Here are the examples using chage -E option.

[root@dev01 ~]# chage -E 2019-05-12 demouser
or
[root@dev01 ~]# chage -E $(date -d +180days +%Y-%m-%d) demouser
[root@dev01 ~]# chage -l demouser
Last password change : never
Password expires : never
Password inactive : never
Account expires : May 12, 2019
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
[root@dev01 ~]#
Total
1
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

Top Open Source Email Servers

Related Posts