Home Learn Linux How to change your password in Linux

How to change your password in Linux

This guide will walk you through the straightforward steps to securely change your password in Linux.

by Hend Adel
Published: Updated:
change the Linux password

Amongst the numerous tasks that you might want to perform on Linux, one of the simplest yet most important ones is changing your password. Like my grandma used to say, “Regularly changing your locks keeps the thieves guessing.” I believe the same holds true for passwords in the digital realm.

In today’s article, we’ll delve deep into the world of Linux passwords, understand their significance, and most importantly, guide you step-by-step on how to change them. So, without further ado, let’s get started.

By the end of this tutorial, you will be able to gain some information about how the password is saved in Linux systems. Also, you can change your password and other users’ passwords. Changing the password can be done using one of the following methods:

  • via the command line
  • via the graphical user interface

Where is the Linux password stored?

However, before changing the password, let’s check first where the password is stored in Linux. As a Linux user, you should know that the password for any Linux user account is saved into two main password configuration files:

  • The /etc/passwd file
  • The /etc/shadow file

The/etc/passwd file contains all the Linux system users, each user’s home directory, group, and other information about each user account. In this file, you can see so many users, but some of these users can log in because the other users are locked until you unlock them. To preview the content of the /etc/passwd file, you can easily use the following command:

cat /etc/passwd
The passwd File Content

The passwd File Content

As you can notice, the /etc/passwd file contains so many users that you are not using, and you probably do not know they even exist. You can scroll down till you reach a row for your user account.

The tuts User Account

The tuts User Account

Previously, the encrypted passwords for each user account were stored in the /etc/passwd file. Nowadays, they are removed from the /etc/passwd file and added to the /etc/shadow file. To preview the content of the /etc/shadow file, you should use the “sudo” command as follows:

sudo cat /etc/shadow
The shadow File Content

The shadow File Content

As you can observe, for each entry in the /etc/passwd file, you will find another corresponding entry in the /etc/shadow file. Also, the /etc/shadow file will contain the last time the password was changed and other information.

The tuts User Account in The shadow File

The tuts User Account in The shadow File

Before moving on to the next section, let’s check how to create a strong password.

The importance of a strong password in Linux

Before diving into the how-to, it’s essential to know the ‘why’. Linux, being a multi-user operating system, relies heavily on user passwords to ensure security and privacy. With strong credentials, you safeguard your data from unauthorized access. The stronger your password, the more resilient your account becomes against potential threats. I’ve personally been a victim of weak password syndrome, and let me tell you, it’s not a pleasant experience.

With that in mind, let’s learn how to change the password.

Change the Linux Password

Change Password via the Command Line or Terminal

We will use the passwd command to change your current user account and other users’ passwords during this method. But be careful. It is highly recommended that you write down the password before logging out.

Change Your Current Password

Step 1. First things first, let’s open a terminal.

Step 2. To change the password of the currently logged-in user, use the following command:

passwd
Change Current Password

Change Current Password

Step 3. As you can notice, to be able to change your password, you will be asked to enter your current one first.

Current Password Changed Successfully Using passwd Command

Current Password Changed

If everything is ok, you will get a message that your password has been updated successfully.

Resetting Password for Another User (For Administrators)

If you’re an administrator (or someone gave you super-user privileges), you can change the password for other users too.

Use the passwd command along with the user account you need to change their password.

sudo passwd User_Account
Change Password For Another User Account

Change Password For Another User’s Account

Unlike changing your password, you will not be asked to enter the user’s password. However, you will be asked directly to enter the new password for the mentioned user.

Additionally, in case you need to change the root password use the following command:

sudo passwd root
Change Password For Root Account

Change Password For Root Account

Force User To Change Password

One more thing, if you need to force a user to change their password the next time they log in, use the password command with the “-e” option as follows:

sudo passwd -e User_Account
Force User To Change Password

Force User To Change Password

You will be informed that the user will be asked to enter a new password they log in.

Change Password via Graphical User Interface

In this method, you will use the built-in settings application to change your password.

Step 1. From the top right of your desktop, click on the drop-down arrow.

Press the Drop Down Arrow

Press the Drop Down Arrow

Step 2. Press the system settings button.

Open the System Settings

Open the System Settings

Step 3. From the left panel, scroll down until you find the Details option.

Select The Details Option

Select The Details Option

Step 4. From the left panel, select the Users option.

Open the Users Menu

Open the Users Menu

Step 5. You will get a screen like the below one with all the defined users appearing as follows:

Users on The Ubuntu

Users of The Ubuntu

Step 6. Users press the Unlock button on the top of the settings screen to edit any of those. Also, you will be asked to enter the sudo password.

Unlock The Settings Screen For Editting

Unlock The Settings Screen For Editing

Step 7. Suppose you need to change your current password. You will double-click on the password field.

Double Click on The Password Field

Double Click on The Password Field

Step 8. Now you will be prompted to enter the current and new passwords.

Enter The Required Fields

Enter The Required Fields

Step 9. You can save your password using the Change button if it is strong enough.

Press The Change Button

Press The Change Button

Step 10. Additionally, to change another user’s password, click on the user and double-click on the password field.

Change The tuts User Account

Change The tuts User Account

Pro tips

Being around Linux for years, I’ve gathered a few tips that might come in handy:

  • Choose a Strong Password: I cannot stress this enough. Your password should be a mix of uppercase letters, lowercase letters, numbers, and special characters. Avoid easily guessable patterns. The days when “password123” was considered okay are long gone, and honestly, they were never really okay.
  • Use a Password Manager: If remembering complex passwords isn’t your forte, consider using password managers. They’re like the little notebooks my aunt used to keep, but digital and way more secure.
  • Don’t Share Your Password: This might seem like a no-brainer, but you’d be surprised how many people casually share their passwords. As much as you trust your best friend, sharing passwords is a strict no-no.
  • Regularly Change Your Password: It’s advisable to change your passwords every 3-6 months. It’s like spring cleaning, but for your digital space. You wouldn’t wear the same clothes for a year. Why keep the same password?

Conclusion

Linux, with its grandeur, can sometimes intimidate newcomers. However, tasks like changing a password remain straightforward. Whether you’re a seasoned user or a newbie who’s just starting out, keeping your account secure with a strong, frequently changed password is essential.

The next time you’re enjoying a cup of coffee or tea, take a moment to remember the last time you changed your password. If it’s been a while, perhaps it’s time to freshen things up! Remember, in the vast digital world, your password is your shield. Wield it wisely.

You may also like

1 comment

dragonmouth September 4, 2021 - 7:07 PM

” I forgot my password, can you help me change it???”
You never did answer THAT question. If you do not remember your current password, you cannot change it. Only someone with root privileges can.

Reply

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.