How to Change the Password for a User in Ubuntu Linux Terminal Using the passwd Command

Security is a fundamental aspect of managing any Linux system, whether it is a personal desktop or a remote web server. One of the most basic security practices is regularly updating user passwords, or resetting a password for a user who has forgotten theirs. In Ubuntu Linux, all password management from the terminal is handled by a single, powerful command: passwd.

How to Change Your Own Password

If you are logged into your own account and simply want to update your current password, you can do so without needing special administrator privileges.

  1. Open your terminal application (or connect to your server via SSH).
  2. Type the following command and press Enter:
    passwd
  3. The system will first prompt you to enter your current password to verify your identity. Type it and press Enter. (Note: When typing passwords in the Linux terminal, no characters or asterisks will appear on the screen. This is a normal security feature. Just type the password and press Enter).
  4. Next, you will be prompted to enter your New password.
  5. Finally, you will be asked to Retype new password to confirm you didn’t make a typo.

If the passwords match and meet the system’s complexity requirements, you will see a “password updated successfully” message.

How to Change Another User’s Password (Admin Only)

If you are the system administrator (root or a user with sudo privileges), you can change the password for any other user on the system. This is necessary if a user forgets their password and is locked out.

To change another user’s password, you must use sudo followed by the passwd command and the specific username.

  1. Open your terminal.
  2. Type the following command, replacing “username” with the actual account name:
    sudo passwd username
  3. Press Enter. Because you used sudo, you will first be prompted to enter your password to authorize the administrative action.
  4. Once authorized, the system will bypass the “current password” check (since you are forcing a reset) and immediately ask you to enter a New password for that user.
  5. Retype new password to confirm.

The user’s password is now changed, and they can log in immediately using the new credentials you just set.

How to Force a User to Change Their Password on Next Login

A common security practice for administrators is to set a temporary password for a user and then force them to create their own secure password the next time they log in. You can do this by expiring their current password.

  1. First, set a temporary password using the method above (sudo passwd username).
  2. Next, type the following command to immediately expire that password:
    sudo passwd -e username

The next time that user attempts to log in (either via the desktop or SSH), the system will accept the temporary password but will immediately halt the login process and force them to choose a new, permanent password before granting them access to the shell or desktop.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.