Introduction
A password is used to authenticate users and prevent unauthorized access to sensitive data. Regularly changing Linux passwords adds an extra security layer and reduces the likelihood of password-based attacks.
The following guide explains how to change a password in Linux.
Prerequisites
- A Linux system (this tutorial uses Ubuntu 22.04).
- Access to the terminal.
- Sudo or root privileges.
How to Change Your Own Password in Linux
To change your password in Linux:
1. Open a terminal window and run the passwd command:
passwd
2. Type in your current password.
3. Enter the new password.
4. Repeat the new password.
The output confirms the password has been changed.
How to Change Another User's Password in Linux
To change the password of a different user:
1. Use the passwd
command with the name of the user for whom you want to change the password. For example, user1:
sudo passwd user1
2. Type in your login password. This is the same password you use to log in to the system.
3. Enter the new password for the user.
4. Repeat the new password.
The output confirms the password change.
How to Change Root Password in Linux
The root password allows users to execute high-privilege commands. To change the root password in Linux:
1. Execute the passwd
command:
sudo passwd root
2. Enter your login password.
3. Enter a new root password.
4. Retype the new root password.
The system confirms the root password has been updated.
How to Force a Password Reset in Linux
Linux passwords never expire by default. However, there is a way to force users to change their passwords the next time they log in. This is necessary in case of a security breach, but it's also useful for enhancing overall security.
Run the following command to force user1 to change the password on the next login:
sudo passwd -e user1
Confirm your password. The user will have to provide a new password the next time they log in.
Conclusion
You know how to change your password, a password belonging to another user, and the root password in Linux. The guide also showed how to force a password reset for other users, an essential task in case of a suspected breach.
If your system provides access to many users, learn how to manage multiple passwords using the chpasswd command.