Overview

This article will be about the first line of defense against unauthorized access to your computer and personal information – passwords, meaning that we’ll explaining the process on how to change password in Linux for an existing user and for other users too.

Main point about the passwords - The stronger your password is the more protected your computer will be. So be sure NOT to use your first or last name, date or place of birth, names of your children, pets or spouses, your home address, words from dictionary etc. The more characters it has, the harder is to break it.

Well, you don’t have to be so cautious if you’re just setting password for your virtual machine meant for local testing. But, for anything else, I strongly advice you to set a strong password.

That said, let’s get straight to business.

Set or change your password in Linux

To set or change your password is pretty easy. Open your terminal and type:

passwd

You’ll be prompted to enter your current password.

After you type your current password you’ll be asked to enter a new password.

change password in Linux

Right after that you’ll be asked to re-enter new password.

change password in Linux

Don’t think that’s an error. This is actually a precaution, a safety measure to ensure that you’ll enter your new password correctly.

If it happens that entered password mismatches you’ll be notified by the system:

change password in Linux

Also, there is possibility that you try to use forbidden words, as I mentioned in the beginning.

change password in Linux

How to change password in Linux for another user

As you probably heard, Linux is multi user environment. User with special privileges (administrative, to be precise) to change things on a system is “super user” or “root”. Name root originates from Unix times when root users where the only ones to have permission to modify root directory, hence the name.

If you stumbled upon a “sudo” command and wondered what it is, you’re about to find out. Sudo, which stands for “super user do” is one of most important commands or “the one command to rule them all”! Yes, it gives you immense power so use it with care. You know, all that “with great power comes great responsibility” and stuff.

Well, enough of chit-chat, back to work. Let’s demonstrate the power of sudo:

sudo -i

Enter your password and you’ll be switched to root’s account. This works on your local machine, don’t expect it to work in enterprise environment in case you’re just a regular user there.

change password in Linux

From root’s account I don’t need to use sudo command, so I just type:

passwd orby(you enter user whose password you want to change)

change password in Linux

How to lock and unlock account in Linux

While logged as root, let’s expand your knowledge on this subject while simultaneously showing you a glimpse of Linux administration. We’ll add another user so we can use it as training ground.

adduser tester(can’t think of more appropriate name for this type of user)

followed by passwd command to set a password for that user:

passwd tester

change password in Linux

Yeah, I wasn’t really creative with password for this user, so system warned me about that, but hey it’s only for educational purposes.

Now you wonder what can we do? Well, for starters we can lock that account:

passwd –l tester

but to test it, we have to exit root, so type:

exit

and you’re back at your account. Now to test whether tester account is locked, type:

su tester

and it will ask you for it’s password. After you type it, you’ re notified that account is inaccessible.

So next step is to unlock it:

sudo passwd –u tester

change password in Linux

Let’s test it now:

“su tester” again, type its password and it’s active again.

How to set expiring password in Linux

Another thing you can do is to set a password to expire, so you’ll force user to change it:

sudo passwd –e tester

So when you try to log in as tester you’ll get this message:

There is another useful switch for passwd command and that is status:

sudo passwd –S tester

change password in Linux

Here we can see all useful info about account:

  1. username
  2. password status: can be P or PS for Password Set, L for Locker and NP for No Password
  3. date of password’s last change
  4. minimum password age
  5. maximum password age
  6. warning period or number of days given to the user to change their password before it expires
  7. inactivity period or number of days after a password expires before it’s locked

Now we can make some changes on tester account.

sudo passwd –w 10 tester
sudo passwd –x 180 tester

Now it’s status looks a bit different:

sudo passwd –S tester

Summary

Let’ review what we have showcased in this article - So, apart from just showing the process on how to change password in Linux for a single user, we also covered how to change another user’s password which gave you a slight insight of how system administration works and we changed account’s maximum age to around six months and extended warning period for user to change password to 10 days.

With that info we came to an end of this article. Till next time, stay productive and thank you for your time!