How to Change User Password in Linux

Suraj Joshi Mar 11, 2025 Linux
  1. Understanding the passwd Command
  2. Changing Another User’s Password
  3. Enforcing Password Policies
  4. Conclusion
  5. FAQ
How to Change User Password in Linux

Changing user passwords in Linux is a fundamental skill for system administrators and users alike. The command-line utility passwd is the go-to tool for this task, allowing you to update passwords securely and efficiently. Whether you’re managing a single-user system or a multi-user environment, knowing how to change passwords is crucial for maintaining security and user access.

In this article, we will walk you through the steps to change user passwords in Linux, utilizing the passwd command, and provide you with tips to ensure your passwords are strong and secure.

Understanding the passwd Command

The passwd command is a powerful utility in Linux that allows users to change their passwords and administrators to manage user accounts. When executed, it prompts the user to enter their current password (if applicable) and then the new password they wish to set. This command is straightforward but comes with options that can enhance its functionality.

To change your own password, simply type:

passwd

Output:

Changing password for user username.
Current password:
New password:
Retype new password:
passwd: password updated successfully

When you run this command, it prompts you for your current password and then asks you to enter the new password twice for confirmation. If everything is entered correctly, you’ll see a message confirming that your password has been updated successfully.

Changing Another User’s Password

As a system administrator, you might need to change another user’s password. This can be done by specifying the username in the passwd command.

To change another user’s password, use the following command:

sudo passwd username

Output:

Changing password for user username.
New password:
Retype new password:
passwd: password updated successfully

In this case, you’ll need to have superuser privileges, which is why we use sudo. This command allows you to change the password without needing to know the current password of the user. After entering the new password twice, you will see a confirmation message indicating the password has been updated.

Enforcing Password Policies

To enhance security, it’s essential to enforce strong password policies. You can set rules regarding password length, complexity, and expiration. This is typically done in the /etc/login.defs file or through the chage command.

For example, to set a password expiration for a user, you can use:

sudo chage -M 90 username

Output:

Changing the maximum number of days between password changes for username

This command sets the maximum number of days a password can be used before it must be changed to 90 days. It’s a good practice to regularly update passwords for enhanced security.

Conclusion

Changing user passwords in Linux is a critical task that enhances security and user management. Utilizing the passwd command, along with understanding how to enforce password policies, empowers you to maintain a secure environment. Whether you’re a system administrator or a regular user, mastering these commands will help you navigate Linux more effectively. Remember, a strong password is your first line of defense against unauthorized access.

FAQ

  1. How do I reset my forgotten password in Linux?
    You can reset your password by booting into recovery mode and using the passwd command.

  2. Can I change a password without knowing the current one?
    Yes, administrators can change any user’s password without knowing the current password using sudo passwd username.

  3. What is the best practice for creating strong passwords?
    Use a mix of upper and lower case letters, numbers, and special characters, and ensure it is at least 12 characters long.

  4. How often should I change my password?
    It’s recommended to change passwords every 60 to 90 days for enhanced security.

  1. Is it possible to disable a user account in Linux?
    Yes, you can disable a user account by using the command sudo usermod -L username.
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Suraj Joshi
Suraj Joshi avatar Suraj Joshi avatar

Suraj Joshi is a backend software engineer at Matrice.ai.

LinkedIn