How to Reset/Change User’s Password in Linux Using passwd Command?

As we already know about passwd command which will help us to Set/Reset/change the users password in Linux system.

root (Super User) can change any user account password in Linux.

If you would like to change the root user password make sure you should become a root to perform it and you should have root privileges to perform it.

If you forgot the root password on CentOS/RHEL systems. Navigate to the following link to reset. To reset the forgotten root password on CentOS 6/RHEL 6 systems. To reset the forgotten root password on CentOS 7/RHEL 7 systems.

Type the passwd command alone in the terminal to change the root user password.

Enter the passwd command and followed by the user name to change the other users password.

Normal user can change their password for his/her own account by entering only passwd command on their shell/terminal.

When you use the passwd command, it will ask you to enter the password twice to change it.

For security reason you need to change your password frequently or at-least once in a month. Make sure you should use the hard and guess password (Alphabet Upper and Lower case letters, numbers and Special Characters (Symbols)) and your password length at-least 10-15 characters.

What’s passwd Command

The passwd command changes passwords for user accounts. passwd also changes the account or associated password validity period.

The user is first prompted for their old password, if one is present. This password is then encrypted and compared against the stored password.

The user has only one chance to enter the correct password. The superuser is permitted to bypass this step so that forgotten passwords may be changed.

After the password has been entered, password aging information is checked to see if the user is permitted to change the password at this time. If not, passwd refuses to change the password and exits.

The user is then prompted twice for a replacement password. The second entry is compared against the first and both are required to match in order for the password to be changed.

Syntax for passwd Command

passwd [Options] [UserName]

How to Change The Root User Password

To change the root user password in Linux, Just type the passwd command alone then you will be prompted to enter the new password twice to change it. Make sure you are in root to perform this.

# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

If you would like to reset the root user password in single command, use the following format.

# echo "new_password" | passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.

How to Change Other User’s Password

To change the other user’s password in Linux, Just type the passwd command followed by the corresponding user name then you will be prompted to enter the new password twice to change it.

# passwd daygeek

Changing password for user 2daygeek.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

If you would like to reset the user’s password in single command, use the following format.

# echo "new_password" | passwd --stdin renu
Changing password for user renu.
passwd: all authentication tokens updated successfully.

How to Check User’s Account Status Information

Use -S option with passwd command to check user’s account status information such as last password change date, locked or unlocked, password expiry minimum and maximum age, etc..,

# passwd -S daygeek
daygeek PS 2019-01-13 0 99999 7 -1 (Password set, MD5 crypt.)

The status information consists of 7 fields as follows

  • 2daygeek : Account login name (UserName)
  • PS : This field indicates whether the user account is locked or not. L locked password, NP User account doesn’t have password and PS Has a usable password.
  • 2019-01-13 : Date of the last password change.
  • 0 : Password expiry minimum age.
  • 99999 : Password expiry maximum age.
  • 7 : Password expiry warning period.
  • -1 : Inactivity period for the password

How to Set The root User Password in Ubuntu Based Desktop?

We all are noticed a problem (There is no root password) on Ubuntu based system when we are trying to upgrade anything on system after fresh install.

By default Ubuntu based distribution doesn’t have the root user password and we need to set by entering the below command.

For doing root user activity such as installing/upgrading/removing package from Ubuntu box, we can do by adding sudo command for every request. Just remember, when sudo asks for a password, it needs corresponding user’s password, and not the root account password.

$ sudo passwd
Enter new UNIX password: Type root password you want
Retype new UNIX password: Retype the root password again
passwd: password updated successfully

Navigate to the following link to know more details about RootSudo on Ubuntu.

Note : To know more about password status with more details, you need to have a look into passwd command options and chage command. We will prepare our next article about chage command and passwd command part-2 with options. Please stay tune with 2daygeek.

You may also like...

Shares
Close
Please support the site
By clicking any of these buttons you help our site to get better