How to Change Password in Linux

April 26, 2024

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.

How to Change 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
passwd terminal output

2. Type in your current password.

type in your new password terminal output

3. Enter the new password.

provide new password terminal output

4. Repeat the new password.

retype new password terminal output

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.

Provide current password terminal output.

3. Enter the new password for the user.

Type in the new password for user1 terminal output.

4. Repeat the new password.

Repeat the new password for user1 terminal output.

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.

sudo passwd root terminal output

3. Enter a new root password.

Provide new root password terminal output.

4. Retype the new root password.

Retype new root password terminal output.

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
sudo passwd -e user1 terminal output

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.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Linux Commands Cheat Sheet
November 2, 2023

A list of all the important Linux commands in one place. Find the command you need, whenever you need it or download our Linux Commands Cheat Sheet and save it for future reference.
Read more
How To Install and Use Linux Screen
April 7, 2022

Screen is a powerful tool for working in the command line. It lets you create, monitor, and switch between several different windows. With Screen, you can multitask much like a graphical interface.
Read more
How to Use the su Command in Linux
April 16, 2024

Learn how to use the su command with practical examples and explanations. Change users in the terminal window or switch to the root in a single step. This article tells you all you need to know about su.
Read more
How to Reset or Change MySQL Root Password on Linux or Windows
December 12, 2023

Like many web services, MySQL has an administrator-level or root password. The root password allows a user to perform all top-level functions in the database.
Read more