Javatpoint Logo
Javatpoint Logo

How to change user password in Linux

The discussed guidelines should work on all Linux distributions, including Ubuntu, Debian, and CentOS.

Here, you will also learn how to force employees to develop their password at next login.

Introduction

In Linux, with the passwd utility, a user account password may be changed.

Encrypted account credentials and other password-related details are contained in a / etc / shadow file.

As a daily user, you need to change your password. The root user and user with the rights of sudo will update the passwords of another user and decide if the password should be used or changed.

When you change your password, make sure that you choose a unique, effective password.

Having a proper password is one of the essential things to secure your account. There are at least 16 characters in a strong password, with at least one upper case letter, one lowercase letter, one integer, and one special character.

It is best to update the password periodically and, for security reasons, use a separate password for each account.

Change Your User Password

Run the passwd command to change your own user account password:

How to change user password in Linux
How to change user password in Linux

You need to type in the password you already have. If the password is right, it will ask you to enter your new password and validate it.

When you type them, the passwords are not displayed on the screen.

Please use your new password when you log in to your device next time.

Change Another User's Password

As indicated in the introduction, only root users and users with access to the sudo account can change the password of another user account.

The example below implies that you are logging in as a sudo privilege owner.

To change the password for another user account, follow the below steps:

  • Run the passwd command, followed by the user name,
  • For example, to modify a user's password called linuxize, run the following command:
How to change user password in Linux

You will be asked to enter and validate the new password:

Output

How to change user password in Linux

The successful command will print something like this:

How to change user password in Linux

Force User to Change Password at Next Login

Passwords are fixed, by default, never expires. To compel a user to change their password the next time they log in, use the passwd command with the ---expire option followed by the username of the user:

How to change user password in Linux

The user's password will expire immediately with the above command.

A message that forces the user to change the password will be displayed the next time the user attempts to log in with the old password:

How to change user password in Linux

Output

How to change user password in Linux

Once a new password is set by the user, the connection will close.


Next TopicAwk Command Usage





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA