<img src="https://ws.zoominfo.com/pixel/6169bf9791429100154fc0a2" width="1" height="1" style="display: none;">
Curious about how StrongDM works? 🤔 Learn more here!
Search
Close icon
Search bar icon

How to Change Password in Linux: A Step-by-Step Guide

StrongDM manages and audits access to infrastructure.
  • Role-based, attribute-based, & just-in-time access to infrastructure
  • Connect any person or service to any infrastructure, anywhere
  • Logging like you've never seen

Like all operating systems, Linux is highly vulnerable to compromised passwords. Recently, one download site served Linux users malware that stole their log-in credentials for more than three years.

That's why regularly changing your passwords in Linux is so important.

This guide will tell you how to do so using simple commands and tools. You'll benefit from the tips below if you're:

  • A regular user wanting to update their password
  • An administrator managing multiple users in a Linux environment
  • Someone trying to reset a forgotten root password

You'll also learn some best practices for securing your Linux system.

Password management is similar across Linux distributions, so system administrators, developers, and regular users can all benefit from this guide.

Tools and Commands for Changing Passwords

You can change passwords with Linux's command-line interface, also known as the terminal.

The most common command is:

passwd

You can use this command to change your own password as well as other users' passwords for both standard and root accounts.

To change your password, simply run "passwd" with Linux's command-line interface.

To change other users' passwords, run the command with superuser privileges by adding "sudo" before "passwd" and then input the username of the person whose password you want to change. Your command should look like this:

sudo passwd <username>

Other commands you might want to use include:

  • chpasswd: great for changing multiple passwords at the same time
  • usermod: helps you lock or unlock user accounts
  • chage: used for managing password expiration policies

How to Change Your Own Password

Changing your password on Linux involves using the "passwd" command and setting your password policies. This process is as follows.

1. Using the 'Passwd' Command

Here's how to change your password in Linux with the "passwd" command:

  • Open the command-line interface.
  • Type "passwd" and press "Enter."
  • Enter your current password when prompted.
  • Enter your new password and confirm it.

Here's an example of the command:

$ passwd

Changing password for user.

Current password: [Enter current password]

New password: [Enter new password]

Retype new password: [Confirm new password]

If your password doesn't meet your security policies, you'll receive an error and will have to try again. 

2. Setting Password Policies

Eighty-four percent of internet users have unsafe passwords for credentials that include their date of birth and other personal information. Learn how to improve your password policies below:

  • To strengthen passwords, administrators can enforce password complexity rules using the "pam_pwquality" module, which is a pluggable authentication module.
  • To change your password expiration policy, use the "chage" command. For example, you can require users to change their passwords every six months.

How to Change Another User's Password

Changing another person's password depends on whether you're a root user or a system administrator.

1. As a Root User

You can change other users' passwords with the "passwd" command if you're a root user. Follow these steps:

  • Open the terminal.
  • Use this command: sudo passwd <username>.
  • Enter your own password to confirm root access.
  • Enter and confirm the new password for the user.

For example:

$ sudo passwd john

Enter new UNIX password: [Enter new password for user]

Retype new UNIX password: [Confirm password]

2. As a System Administrator

The "chpasswd" command lets you batch-change other users' passwords or automate user management as a system administrator.

Here's an example of scripting "chpasswd" for multiple users:

$chpasswd

user1:user1_password

user2:user2_password

user3:user3_password

If you want to improve your Linux security further, StrongDM can help. Our platform simplifies authentication, access management, and activity monitoring, helping you create a safer Linux environment for everyone.

Resetting Forgotten Passwords in Linux

Thankfully, you can quickly reset forgotten passwords in Linux, no matter whether you're a standard or root user.

1. For Standard Users

If you've forgotten your password but have root access, simply use the "passwd" command to reset it:

sudo passwd <your_username>

Then, follow the prompts to set a new password.

2. For Root Users

If you don't know the root password, follow these steps:

  • Restart your system and boot into recovery mode (GRUB menu).
  • Drop to the root shell prompt.
  • Use the passwd command to set a new password for root.
  • Reboot the system after resetting.

This method helps you regain access without having to reinstall Linux.

Advanced Password Management

Here are some tips for more advanced password management in Linux.

1. Password Expiration and History Policies

Linux lets administrators enforce password expiration policies with the "chage" command. To check a user's expiration status, use this command:

sudo chage -l <username>

To force a user to change their password at the next log-in, use this command:

sudo chage -d 0 <username>

This command ensures users regularly update their passwords, which can improve your system's security.

2. Locking and Unlocking User Accounts

The "usermod" command temporarily prevents a user from logging in.

  • To lock an account, run the following: sudo usermod -L <username>.
  • To unlock an account, run the following: sudo usermod -U <username>.

These commands are useful if you suspect someone has compromised an account or you need to revoke a user's access to your system.

Conclusion

Linux lets you improve your password management by running different commands and tools. That way, you can update your credentials, reset forgotten details, and control system access. By requiring complex passwords and keeping your system up to date, you can make your Linux environment more secure.

Now, you can take your security to the next level with StrongDM. Our Zero Trust Privileged Access Management platform helps you improve your authentication process, monitor activity, streamline access management, and ensure the secure management of root credentials. As a result, you can rest easy that only authorized persons have access to your Linux system.

Book a StrongDM demo today.


About the Author

, Zero Trust Privileged Access Management (PAM), the StrongDM team is building and delivering a Zero Trust Privileged Access Management (PAM), which delivers unparalleled precision in dynamic privileged action control for any type of infrastructure. The frustration-free access stops unsanctioned actions while ensuring continuous compliance.

StrongDM logo
đź’™ this post?
Then get all that StrongDM goodness, right in your inbox.

You May Also Like

How to List Users in Linux (9 Methods with Examples)
How to List Users in Linux (9 Methods with Examples)
Need to keep tabs on who has access to your organization’s Linux system? This guide explores nine methods, with examples, that can help you quickly list users.
SCP Command in Linux: 10 Essential Examples
SCP Command in Linux: 10 Essential Examples
Discover 10 ways to leverage the SCP command in Linux. Learn how to incorporate options for specific file transfers and how to deal with common errors.
How To Use SSH to Connect to a Remote Server (Windows, Linux & Mac)
How To Use SSH to Connect to a Remote Server (Windows, Linux & Mac)
Secure Shell (SSH) is one of the most effective ways to access and manage remote systems. This technology encrypts communications between the client and the server, enhancing system security and preventing unauthorized access. Another important benefit of SSH is its simplicity. This technology is relatively easy to use with various tools and clients, as we will demonstrate below. Plus, you can also use SSH for file transfers, running commands, and even tunneling. This guide explains how to use SSH to connect to remote servers across Windows, Linux, and MacOS environments.
How to Create Users in Linux with useradd (Step-by-Step)
How to Create Users in Linux with useradd (Step-by-Step)
Setting permissions, revoking access, and performing other user management duties in Linux can improve your system's security and organization, ensuring users can access the resources they need when they need to. The useradd command lets you create, modify, and check user accounts, helping you handle multi-user environments across various Linux distributions.
How to Extract or Unzip .tar.gz Files in Linux (With Examples)
How to Extract or Unzip .tar.gz Files in Linux (With Examples)
A .tar.gz file is a compressed archive file format that combines the tar and gzip formats. These files are popular among system administrators, developers, and regular computer users for archiving and compression. You might need to extract or unzip .tar.gz files if you're transferring big datasets or distributing software with Linux, the third-most popular desktop operating system in the world.