How To Change Password Linux – Using Passwd Command Line

You are only a few commands away from tightening security on your Linux system. Knowing how to change password linux is a fundamental skill for any user, whether you manage a server or use a desktop distribution. This guide walks you through every method, from the terminal to graphical interfaces, ensuring your accounts stay protected.

Passwords are your first line of defense. Changing them regularly reduces the risk of unauthorized access. Linux offers multiple ways to update passwords, and this article covers them all in simple steps.

Let’s start with the most common method: the command line. It works on every Linux distribution, from Ubuntu to CentOS.

Changing Password Via The Terminal

The terminal is the fastest way to update your password. You don’t need any special tools—just a shell prompt.

Step 1: Open The Terminal

Press Ctrl + Alt + T on most desktop systems. If you’re on a server, you’re already logged into a terminal session.

Step 2: Run The Passwd Command

Type passwd and press Enter. The system will prompt you for your current password.

Step 3: Enter Your Current Password

Type your existing password. Nothing appears on screen as you type—this is normal for security.

Step 4: Set A New Password

Enter your new password. You’ll be asked to type it again for confirmation. Choose a strong password with a mix of letters, numbers, and symbols.

Step 5: Verify Success

You’ll see a message like “passwd: password updated successfully.” Your password is now changed.

That’s the basic process. But what if you need to change another user’s password? Or force a password change at next login? Keep reading.

How To Change Password Linux For Another User

If you have sudo privileges, you can change passwords for any user on the system. This is useful for administrators managing multiple accounts.

  1. Open a terminal.
  2. Type sudo passwd username (replace “username” with the actual account name).
  3. Enter your sudo password when prompted.
  4. Set the new password for that user.
  5. Confirm the change.

You won’t need the user’s current password. This bypasses the normal verification process, so use it carefully.

Forcing A Password Change At Next Login

Sometimes you want a user to create their own password. Use the chage command to expire their current password.

  1. Run sudo chage -d 0 username.
  2. The user will be forced to change their password on next login.
  3. They’ll follow the standard passwd prompts.

This method is great for new accounts or after a security incident.

Using The Passwd Command With Options

The passwd command has several useful flags. Here are the most common ones:

  • passwd -l username – Locks the account (prevents login).
  • passwd -u username – Unlocks a locked account.
  • passwd -d username – Deletes the password (makes account passwordless).
  • passwd -S username – Shows password status (locked, active, etc.).

Use these options with caution. Locking an account can lock out legitimate users.

How To Change Password Linux In Graphical Interface

Not everyone loves the terminal. Most desktop environments offer a graphical way to change passwords.

Ubuntu (GNOME)

  1. Open Settings from the system menu.
  2. Go to “Users” or “User Accounts.”
  3. Click on your account.
  4. Select “Password” and click “Change.”
  5. Enter your current password, then the new one.
  6. Confirm and save.

KDE Plasma

  1. Open System Settings.
  2. Go to “User Accounts.”
  3. Click “Change Password.”
  4. Follow the prompts.

Linux Mint (Cinnamon)

  1. Open the Menu and go to “System Settings.”
  2. Click “Login Window” or “User Accounts.”
  3. Select your user and click “Change Password.”
  4. Enter old and new passwords.

Graphical methods are intuitive but slower than the terminal. They work best for casual users.

Resetting A Forgotten Password

What if you forget your password? Don’t panic. You can reset it using recovery mode or a live USB.

Method 1: Using Recovery Mode (GRUB)

  1. Reboot your system.
  2. Hold Shift (or press Esc) during boot to enter GRUB menu.
  3. Select “Advanced options” then “Recovery mode.”
  4. Choose “root” to drop to a root shell.
  5. Remount the filesystem as writable: mount -o remount,rw /.
  6. Type passwd username and set a new password.
  7. Reboot with reboot.

Method 2: Using A Live USB

  1. Boot from a Linux live USB (like Ubuntu installer).
  2. Open a terminal.
  3. Mount your root partition: sudo mount /dev/sda1 /mnt (adjust device name).
  4. Chroot into the system: sudo chroot /mnt.
  5. Run passwd username.
  6. Exit and reboot.

Both methods require physical access to the machine. If you’re on a remote server, you may need to contact your hosting provider.

Password Policies And Security Best Practices

Changing passwords is only part of the equation. Strong policies keep your system safe.

Set Password Expiration

Use chage to enforce regular changes:

  • sudo chage -M 90 username – Password expires after 90 days.
  • sudo chage -m 7 username – Minimum 7 days before password can be changed again.
  • sudo chage -W 7 username – Warn user 7 days before expiration.

Enforce Password Complexity

Install libpam-pwquality on Debian/Ubuntu or pam_pwquality on RHEL/CentOS. Configure it in /etc/security/pwquality.conf:

  • minlen = 12 – Minimum password length.
  • dcredit = -1 – Require at least one digit.
  • ucredit = -1 – Require one uppercase letter.
  • ocredit = -1 – Require one special character.

Use SSH Keys For Remote Access

For servers, consider disabling password-based SSH login. Generate an SSH key pair and use it instead. This eliminates password risks entirely.

Common Mistakes And Troubleshooting

Even experienced users hit snags. Here are typical issues and fixes.

“Password Too Short” Error

Your password doesn’t meet minimum length requirements. Use at least 8 characters, or adjust minlen in PAM settings.

“Password Not Changed” Message

You might have entered the wrong current password. Double-check your typing. Caps Lock can cause this.

Cannot Change Password For Root

Root password changes require root privileges. Use sudo passwd (without a username) to change root’s password.

Account Locked After Too Many Attempts

Some systems lock accounts after failed login attempts. Wait a few minutes or contact an admin to unlock it.

Passwd Command Not Found

This is rare but can happen in minimal containers. Install the passwd package via your package manager.

Automating Password Changes With Scripts

System administrators often need to change multiple passwords. A simple bash script can help.

#!/bin/bash
# Change password for a list of users
for user in alice bob charlie; do
    echo "$user:newpassword123" | sudo chpasswd
done

Replace “newpassword123” with a secure password. For better security, generate random passwords using openssl rand -base64 12.

Automation saves time but introduces risk. Always test scripts in a safe environment first.

Password Managers And Linux

Using a password manager simplifies password management. Popular options include:

  • Bitwarden – Open source, cross-platform, with CLI tools.
  • KeePassXC – Local database, no cloud dependency.
  • pass – The standard Unix password manager, uses GPG.

These tools generate strong passwords and store them securely. You only need to remember one master password.

How To Change Password Linux For Service Accounts

Service accounts (like www-data or mysql) often have passwords too. Change them the same way:

  1. sudo passwd serviceaccount
  2. Set a strong password.
  3. Update any configuration files that use this password.

Be careful: changing a service account password can break applications. Update related configs immediately.

Using The Chpasswd Command

The chpasswd command reads password changes from stdin. It’s useful for batch updates.

echo "username:newpassword" | sudo chpasswd

You can also pipe a file:

sudo chpasswd < users.txt

Each line in users.txt should be username:password. This method is fast but less secure if the file is exposed.

Passwordless Login And Alternatives

Some modern systems move away from passwords entirely. Consider these alternatives:

  • SSH keys – Cryptographic key pairs for authentication.
  • Biometrics – Fingerprint or facial recognition (hardware dependent).
  • Two-factor authentication – Combine password with a time-based code.

These methods reduce reliance on passwords while improving security.

Frequently Asked Questions

How Do I Change My Password In Linux Without Knowing The Old One?

You need root or sudo privileges. Use sudo passwd username to set a new password without the old one.

Can I Change The Root Password From A Regular User Account?

Yes, if you have sudo access. Run sudo passwd to change the root password.

What Is The Difference Between Passwd And Chpasswd?

passwd is interactive and prompts for passwords. chpasswd reads passwords from stdin, making it suitable for scripts.

How Often Should I Change My Linux Password?

Every 60 to 90 days is standard. Use chage to enforce expiration policies.

Does Changing My Password Affect Running Processes?

No, processes continue running. However, any service using the old password (like cron jobs) will fail until updated.

Final Thoughts On Password Management

Changing your password on Linux is a quick process that significantly improves security. Whether you use the terminal or a graphical tool, the steps are straightforward. Remember to choose strong passwords, enforce policies, and consider alternatives like SSH keys for remote access.

Regular password changes are a habit worth developing. They protect your data and your system from unauthorized access. With the commands and techniques in this guide, you can manage passwords confidently on any Linux distribution.

Keep your system secure by staying proactive. Update passwords periodically, monitor account activity, and educate other users on best practices. A few minutes of effort now can save hours of recovery later.