Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
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:
Let’s start with the first one.
Table of Contents
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:
Sounds complex? Here’s how you do it:
passwd
If you want to change the password of another user, you’ll have to follow two steps:
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
Next, change the password using the passwd
command as shown here:
passwd
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
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
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.
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.