How to Change Password in Linux

By
Sara Zivanov
Published:
April 26, 2024
Topics:

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