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:
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.
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
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.
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:
Step 3. As you can notice, to be able to change your password, you will be asked to enter your current one first.
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
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
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
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.
Step 2. Press the system settings button.
Step 3. From the left panel, scroll down until you find the Details option.
Step 4. From the left panel, select the Users option.
Step 5. You will get a screen like the below one with all the defined users appearing as follows:
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.
Step 7. Suppose you need to change your current password. You will double-click on the password field.
Step 8. Now you will be prompted to enter the current and new passwords.
Step 9. You can save your password using the Change button if it is strong enough.
Step 10. Additionally, to change another user’s password, click on the user and double-click on the password field.
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?
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.