4 Best Methods to Change User Password Linux

Written by

Reviewed by

Last updated: July 11, 2024

Expert verified

SVG Image

TL;DR

To change user password Linux, follow these steps:

  1. Open a terminal.
  2. Type passwd username, replacing username with the actual username.
  3. Enter the current password when prompted.
  4. Type the new password and confirm it.

Continue reading the guide below to learn different methods to change user password Linux and common errors that can occur during the process.

Keeping your Linux system secure is crucial, and managing passwords effectively is a big part of that. If you need to change your password, reset a forgotten password, or update a root password, there are straightforward methods to help you. In this post, I’ll guide you through various ways to manage passwords in Linux, ensuring your system stays secure. You’ll learn how to change user passwords using different commands, force password resets, and follow best practices to maintain robust security. Let’s dive in and get your system secure!

Importance of Regularly Updating Passwords

Regularly updating passwords is a key practice for maintaining robust security in any system. Here are some of the main reasons why frequent password changes are essential:

  • Prevent Unauthorized Access: Changing passwords regularly helps protect against unauthorized access. Hackers often use old passwords from previous data breaches to gain entry into systems.
  • Mitigate Security Risks: Frequent updates minimize the risk of using compromised passwords, reducing the chances of security breaches.
  • Protect Sensitive Data: Regular password updates help ensure that sensitive information remains secure and inaccessible to unauthorized users.
  • Enhance System Security: Keeping passwords fresh strengthens the overall security of the system, making it harder for attackers to exploit vulnerabilities.

How to Change User Password Linux

To change user password Linux, open the terminal and type passwd username, replacing username with the actual username. Enter the current password if prompted, then type the new password twice to confirm. For changing another user’s password, use sudo passwd username. This method ensures secure password updates for maintaining system security.

That was the quick answer. Keep reading for the detailed steps to Linux change user password using this and three more methods.

1. Using the passwd Command

The passwd command is the most commonly used method to change user passwords in Linux. Its purpose is to provide a straightforward and efficient way to update passwords, ensuring account security and preventing unauthorized access. Follow these steps to change password in Linux:

  1. Open a Terminal window.
opening terminal 20
  1. Type the following command and press Enter:
passwd username

Replace username with the username of the account whose password you want to change. You will be prompted to enter the current password.

changing password of user
  1. Next, enter the new password and confirm it when prompted. Note that the password characters will not be displayed as you type for security purposes. Once you’ve successfully changed the password, a confirmation message will be displayed.
assigning new password

2. Utilizing the chpasswd Command

The chpasswd command streamlines the process of changing passwords for multiple users simultaneously. It offers the benefit of time-saving efficiency when managing a large number of user accounts, making it ideal for system administrators or situations that require bulk password changes. Follow these steps to change password Linux:

  1. Access your command prompt and create a text file, such as passwords.txt.
creating a text file
  1. Enter the username-password pairs in the following format:
username1:password1
username2:password2

Replace username1, username2, and so on, with the actual usernames, and password1, password2, and so forth, with the desired passwords.

  1. Save the file and remember its location.
saving the text file after adding the context
  1. In the Terminal, type the following command and press Enter:
sudo chpasswd < passwords.txt

Replace passwords.txt with the path to the file you created.

  1. The chpasswd command will read the file and change the passwords for the specified users accordingly.
changing passwords of users through a text file

3. Employing the usermod Command

The usermod command serves a dual purpose, allowing you to modify user account settings and change passwords. It’s particularly useful for system administrators who need to manage multiple aspects of user accounts efficiently. Follow these steps to usermod change password:

  1. Launch the Terminal window and execute the following command and press Enter:
sudo usermod --password new_password username

Replace new_password with the desired password and username with the username of the account you want to modify.

changing password of user using usermod command

4. GUI Method

GNOME offers a graphical interface for changing passwords. Its purpose is to provide a user-friendly experience for those who prefer a visual approach to password management. Follow these steps to Linux set user password using GUI:

  1. Click on the gear icon in the top-right corner of the desktop to open System Settings.
opening system settings 2
  1. In the System Settings window, click on User Accounts.
opening users section from settings
  1. If there are multiple user accounts listed, select the account for which you want to change the password. Click on the Password field.
selecting user to change password
  1. Enter the current password for the user account. Enter the new password you want to set.
  2. Retype the new password a second time to confirm it. Finally, click the Change button to save the new password.
changing password using GUI

How to Change Another User’s Password in Linux

Changing another user’s password is a common administrative task in Linux. This is particularly useful when a user forgets their password or if the password needs to be updated for security reasons. The sudo command allows administrators to execute commands with superuser privileges. This is essential when changing another user’s password, as it requires higher-level permissions.

  1. Access the terminal application on your Linux system.
  2. Type the following command and press Enter. 
sudo -i

You will be prompted to enter your password to gain superuser access.

logging as a super user
  1. Use the passwd command followed by the username. For example:
sudo passwd username

Replace username with the actual username of the account whose password you want to change.

chaning password of a user
  1. You will be prompted to enter the new password twice for confirmation.
setting new password

How to Change Root Password in Linux

The root account has unrestricted access to the entire system, making it crucial to maintain its security. Changing the root password periodically helps protect your system from unauthorized access. The sudo passwd root command allows you to change the root password by elevating your privileges to those of the root user.

Explore this guide to learn different methods to add root permissions to users in Linux

Follow these steps to change root password:

  1. Open the Terminal and execute the following command:
sudo passwd root

You will be prompted to enter your current user password to verify your identity.

changing password of a root user
  1. Enter the new password for the root account and confirm it.
setting new password for root user

How to Force a Password Reset

Forcing a password reset can be necessary for maintaining security, especially if there has been a potential security breach or if you need to enforce a password change policy.

  1. Launch your Terminal window and use the following command followed by the username.
sudo passwd --expire username

Replace username with the actual username of the account you wish to expire the password for.

force resetting password of a user
  1. Upon the next login, the user will be prompted to change their password.
prompted to change user password on login

Best Practices for Linux Password Management

Managing passwords effectively in Linux is crucial for system security. By following these best practices, you can enhance the protection of user accounts and prevent unauthorized access.

  • 🔒 Use Strong, Unique Passwords: Ensure all passwords are strong and unique, combining letters, numbers, and special characters. Avoid common words and use a password manager to generate and store passwords securely.
  • 🔄 Regularly Update Passwords: Change passwords periodically to minimize the risk of unauthorized access. Set a reminder to update passwords every three to six months.
  • 🛠️ Enable Two-Factor Authentication: Add an extra layer of security by enabling two-factor authentication (2FA) for user accounts. This requires a second form of verification, such as a mobile app code.
  • 📊 Perform Regular Security Audits: Conduct regular security audits to check for weak or compromised passwords. Use tools like John the Ripper or Hydra to identify vulnerabilities and strengthen password policies.

Linux Change Password: In a Nutshell

In this article, I have covered various methods for changing passwords in Linux, including changing other users’ passwords, forcing password resets, and updating the root password.

Frequently Asked Questions

How can I recover a lost root password in Linux?

If you find yourself in a situation where the root password is lost or forgotten in a Linux system, there are ways to recover it. One method is to boot into the system’s recovery mode, which provides a root shell where you can reset the password. Another approach is to use a live CD/USB, which allows you to access the system’s files and modify the password database. It’s important to note that the specific steps may vary depending on the Linux distribution you are using. For detailed instructions tailored to your distribution, refer to the official documentation or consult the community resources associated with your Linux distribution.

Can I change another user’s password as root user?

As the root user in a Linux system, you have the authority to change the passwords of other user accounts. This can be accomplished by utilizing the passwd command followed by the username of the account you wish to modify. By executing this command as the root user, you can specify a new password for the chosen user account. It’s essential to exercise caution and ensure that you have the necessary privileges and permissions before changing another user’s password. Always double-check the username and follow proper security practices when performing administrative tasks.

How can I view the password policy settings in Linux?

To view the password policy settings in Linux, you can explore the /etc/login.defs file. This file contains various configuration parameters related to user authentication and password policies. By examining its contents, you can gain insights into the password-related settings established on your system. Additionally, you can make use of the pam_tally2 and pam_pwquality commands. These commands provide information about the configured password policies and can help you assess the complexity requirements, password expiration rules, and other relevant parameters that govern the password policies in your Linux system.

Are there any tools available for generating strong passwords?

Absolutely! Numerous tools are available for generating strong and secure passwords in Linux. These tools aim to create complex passwords that are difficult to guess or crack. Popular options include pwgen, a command-line tool that generates random passwords based on customizable parameters. Another well-known tool is KeePassXC, a password manager that stores passwords securely and includes a password generator feature. Additionally, online password generators generate strong passwords directly from a web browser. When using these tools, always prioritize the security and confidentiality of your generated passwords.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Install OneDrive on Ubuntu [16 Simple Steps]

Next Post

How to Know What Shell You are Using? [7 Proven Methods]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next