The passwd command is the standard way to change any user's password in Linux

To change a password in Linux, you use the passwd command followed by the username. If you are changing your own password, type passwd alone at the terminal. If you are the root user or have sudo access, you can change another user's password by typing sudo passwd username, replacing "username" with the actual account name.

The system will prompt you to enter a new password twice — once to set it, and once to confirm it matches. Linux does not display what you type for security reasons, so you will not see dots or asterisks as you type. This is normal.

The password takes effect when ready. The user does not need to log out and back in, though some systems may require a new login session before the change fully applies to all services.

Key Takeaways

  • Use passwd alone to change your own password, or sudo passwd username to change another user's password if you have root or sudo access.
  • You must type the new password twice to confirm it, and the terminal will not display what you type.
  • The password change takes effect when ready for most login methods, though some services may require a new session.
  • If you forget your own password and cannot log in, you will need physical access to the machine or help from someone with root access to reset it.
  • Strong passwords should be at least 12 characters and mix uppercase, lowercase, numbers, and symbols to resist guessing attacks.

Changing your own password step by step

Open a terminal and type passwd with no arguments. Press Enter. The system will ask you to enter your current password first — this confirms you have the right to change it. Type your current password and press Enter.

Next, you will see the prompt "New password:". Type your new password and press Enter. You will not see the characters you type. Then the system asks you to retype the new password to confirm it matches. Type it again and press Enter.

If the two entries match, the system confirms the change with a message like "passwd: password updated successfully". If they do not match, the system rejects the change and asks you to try again. If your new password is too straightforward or too short, the system may warn you but still allow it — the warning is informational, not a block.

Changing another user's password as root or with sudo

If you have root access or sudo privileges, you can reset another user's password without knowing their current one. This is useful when a user forgets their password or when you are setting up a new account. Type sudo passwd username, replacing "username" with the account you want to change. Press Enter.

The system will ask for your own password (the one for the account you are currently logged in as), not the target user's password. This confirms you have sudo authority. Type your password and press Enter.

Then you will see "New password:" for the target user. Type the new password and press Enter, then retype it to confirm. The system will confirm the change. The target user can now log in with the new password.

What to do if you forget your own password

If you cannot log in because you forgot your password, you have two main paths. The first requires physical access to the machine: restart the computer, interrupt the boot process (usually by holding Shift or Esc during startup), and enter single-user or recovery mode. From there, you can reset your password without knowing the old one. The exact steps vary by Linux distribution.

The second path is to ask another user with root or sudo access to reset it for you using the sudo passwd command described above. If no one else has access and you cannot reach recovery mode, you may need to reinstall the system or contact your system administrator.

Password requirements and security practices

Linux does not enforce a single password policy across all systems — the rules depend on your distribution and how your administrator has configured it. Some systems require a minimum length (often 8 to 12 characters), a mix of character types, or a certain age before you can change it again.

For your own security, use a password at least 12 characters long and mix uppercase letters, lowercase letters, numbers, and symbols. Avoid dictionary words, personal information, or patterns. A passphrase — a sequence of random words — is often stronger and easier to remember than a random string of characters.

If your system shows a message like "BAD PASSWORD: The password is too similar to the last one" or "BAD PASSWORD: The password contains the user name", the system is rejecting your choice. Try a password that is more different from your previous one, or one that does not include your username.

Changing passwords for service accounts and system users

Service accounts — accounts that run background processes rather than human users — can have their passwords changed the same way as regular accounts. However, if a service reads the password from a configuration file, you must also update that file after changing the password, or the service will fail to start.

System users like "www-data" (for web servers) or "postgres" (for databases) often do not have login shells and are not meant to be logged into directly. You can still change their passwords with sudo passwd, but the change only matters if something is configured to use that password. In most cases, services authenticate using other methods like SSH keys or socket connections, so a password change has no effect.

Troubleshooting common password change errors

If you see "Permission denied", you do not have the right to change that user's password. Regular users can only change their own password. To change another user's password, you must be root or have sudo access.

If you see "passwd: Authentication token manipulation error", the system cannot write the new password to disk. This usually means the filesystem is read-only or the password file is locked. Restart the system or contact your administrator.

If the system says "passwd: user does not exist", you typed the username wrong or the account has been deleted. Double-check the spelling and verify the account exists by running id username.

Frequently Asked Questions

Can I change a password without typing it twice?

No. Linux requires you to type the new password twice to catch typos. If you type it differently the second time, the system rejects the change and asks you to start over. This prevents you from locking yourself out with a password you cannot remember.

What happens if I change a password while the user is logged in?

The user remains logged in with their current session. The new password takes effect the next time they log in. Some services that cache credentials may not recognize the change until they restart or their session expires.

Can I see what password I just set?

No. Linux does not display passwords for security reasons, even after you have set them. If you need to verify a password works, log out and log back in with the new one, or ask the user to test it themselves.

How do I change a password over SSH from a remote machine?

Log in to the remote machine via SSH and run passwd or sudo passwd username just as you would on the local machine. The password change happens on the remote system and takes effect when ready for future logins to that machine.

Is there a way to force a user to change their password on next login?

Yes. As root or with sudo, run sudo passwd -e username. This marks the password as expired. The next time that user logs in, the system will force them to choose a new password before they can access their account.