Enter your email address below and subscribe to our newsletter

How to Change User Password in Linux

Learn how to use the passwd command to change password in Linux for different users.

Share your love

There are multiple reasons why one would want to user’s password. Being a user, you’d want to change your password for security reasons such as the password is not strong enough or you were given a generic password from your organization and now you want to make it robust.

On the other hand, if you are a system admin, then you might want to force users to change their passwords. So in this tutorial, I will walk you through the following:

  • How to change the password of the current user
  • How to change the password of another user
  • How to change the password of the root user
  • Force users to change their password at the next login

Let’s start with the first one.

How to change the password of the current user

If you want to change the password of the current user, all you have to do is execute the passwd command in the terminal. Once you execute the passwd command, it will ask you the following:

  • Enter your current password
  • Enter the new password twice for the confirmation

Sounds complex? Here’s how you do it:

passwd
Change password of the current user in Linux

How to change the password of another user

If you want to change the password of another user, you’ll have to follow two steps:

  1. Log in as a user of which you want to change the password.
  2. Use the passwd command to change the password of the logged-in user.

Here’s how you do it.

First, use the su command in the following manner to switch to the target user:

su - <username>

For example, I want to change the password for the user team, so I will first log in as the user team using the following:

su - team
Switch to different user account in Linux

Next, change the password using the passwd command as shown here:

passwd
Change password of a different user in Linux

How to change the password of the root user

There are many Linux distributions like Ubuntu which does not have the option to configure a root user while installation so you end up having a locked root account.

So when you try to switch to the root account using su - command, it will ask you for a password and as you have not configured the root user so far, how you are supposed to enter the password.

In that case, you can change the password of the root user by appending the root as a target user to the passwd command as shown here

sudo passwd root
Change the root account password in Linux

Force user to change password at next login

While there are various ways you can force a user to change the password at the next login, I will stick to the passwd command to stay relevant to this guide.

To force the user to change the password at the next login, use the passwd command with the --expire in the following manner:

sudo passwd --expire [username]

Let’s say I want to force the user team to change his password at the next login, then I’ll use the following command:

sudo passwd --expire team
Force user to change password at the next login in Linux

As you can see, after executing the passwd command, when I switched the user team and it forced me to change the password before anything else.

Wrapping Up…

In this tutorial, I went through how you can change the password of the current user, another user, root user and even force a specific user to change his password at the next login.

Sure, there are other advanced ways to change passwords such as using the chage command, but it is a different purpose utility and will cover it in the future.

Also, if you have any suggestions or questions, then feel free to drop us a comment, and we will reach out to you as soon as possible.

Share your love
Kabir
Kabir

A tech journalist whose life revolves around networks.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!