4 Best Methods to Change or Set User Password in Linux

Written by

Reviewed by

Last updated: June 27, 2023

Expert verified

SVG Image

TL;DR

To change or set user password in Linux, you can try these four methods:

  1. Change user passwords in Linux through the Terminal by executing the command: passwd username.
  2. Update passwords for multiple users simultaneously using a text file with the command: sudo chpasswd < passwords.txt.
  3. Modify user account settings, including password changes, using the command: sudo usermod --password new_password username.
  4. Change passwords through the graphical interface in GNOME environment.

To ensure a smooth password management process in Linux, familiarize yourself with common errors like “Permission Denied,” “Invalid Current Password,” “Password Complexity Requirements Not Met,” and “Password Change Failed – Try Again Later.” Understand these errors to troubleshoot and overcome obstacles, ensuring a secure password management workflow.

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

Password security is of paramount importance in Linux systems. With the increasing prevalence of password-related breaches, it is crucial to understand how to change or set user password in Linux effectively. By changing passwords periodically and implementing strong password practices, you fortify your defenses against unauthorized access, hacking attempts, and data breaches. In this article, I will explore the methods to change or set user password in Linux and common errors that can occur during the process.

How to Change or Set User Password in Linux

To change or set a user password in Linux, you have multiple options available. You can use the passwd command in the Terminal for a straightforward approach, the chpasswd command for changing passwords for multiple users simultaneously, the usermod command to modify user account settings including passwords, or using GNOME for a user-friendly graphical interface.

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 a password:

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

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:

  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:
<strong>username1:password1</strong>
</strong>username2:password2</strong>

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:
<strong>sudo chpasswd < passwords.txt</strong>

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. Here’s how you can change a password using usermod:

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

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:

  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

4 Common Errors When Changing or Setting User Passwords

It is essential to familiarize yourself with common errors to troubleshoot and overcome any obstacles you may encounter while changing or setting user passwords in Linux. By understanding these errors and their resolutions, you can ensure a smooth and successful password management process. Here are four common errors:

  • 🔐 “Permission Denied” error: One common error that users encounter when changing or setting user passwords in Linux is receiving a “Permission Denied” message. This error occurs when you do not have sufficient privileges or are not executing the command as the root user. To resolve this, ensure that you are logged in as the root user or use the sudo command to elevate your privileges before attempting to change or set a password.
  • ❗️ “Invalid Current Password” error: Another error that users may face is receiving an “Invalid Current Password” notification when trying to change a password. This error typically occurs when the user enters an incorrect current password. Double-check the current password to ensure its accuracy. If you are unsure of the current password or have forgotten it, you may need to follow the steps for password recovery or contact your system administrator for assistance.
  • ⛔️ “Password Complexity Requirements Not Met” error: Some Linux systems have password complexity requirements to ensure stronger security. In this case, users may encounter an error indicating that the password complexity requirements have not been met. This error occurs when the newly chosen password does not meet the specified criteria, such as minimum length, character types, or disallowed patterns. To resolve this, choose a password that satisfies the complexity requirements, usually involving a combination of uppercase and lowercase letters, numbers, and special characters.
  • “Password Change Failed – Try Again Later” error: Occasionally, users may come across an error message stating that the password change has failed and to try again later. This error can occur due to various reasons, such as system maintenance, temporary connectivity issues, or conflicting processes. If you encounter this error, it is advisable to wait for a while and attempt to change the password again. If the issue persists, it may be necessary to investigate further or seek assistance from your system administrator to resolve the underlying cause.

In a Nutshell

In this article, I have provided a comprehensive understanding of how to change or set user password in Linux systems. By following the command-line and graphical methods outlined in this guide and by avoiding common errors that can occur, you can enhance the security of your Linux accounts and protect your valuable data from potential breaches.

However, the world of Linux administration and security offers a multitude of topics to explore further. To deepen your knowledge, consider the following areas, Advanced User Management, Two-Factor Authentication, and Linux Hardening. Stay curious, continue learning, and use the rich resources available online to enhance your Linux administration skills further. Secure and efficient systems await you!

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

3 Ways to Check Which Shell You are Using on Linux

Leave a Reply

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

Read next