Skip to content
Log In Sign Up info@muvcloud.com

Change Your Own Password

Run passwd with no arguments:

passwd

It asks for your current password first, then for the new one twice. Nothing appears on the screen while you type, not even asterisks; that is normal. Most systems check the new password against rules for length and complexity and refuse one that is too short or too close to the old one.

Change Another User's Password

With sudo rights you can set a new password for any account without knowing the old one:

sudo passwd deploy

This works the same on Ubuntu, Debian, AlmaLinux, and Rocky Linux. An account created with useradd has no usable password until you set one this way; the difference between the account tools is in useradd vs adduser. For the root account itself, see how to change the root password in Ubuntu.

Force a Change at the Next Login

When you give someone a temporary password, make it expire at once so that they have to choose their own:

sudo passwd -e deploy

chage does the same by setting the date of the last change to day zero:

sudo chage -d 0 deploy

At the next password login, the user types the temporary password and is then asked for a new one before the session starts.

Read and Set Password Aging

sudo chage -l deploy

The output lists the date of the last change, when the password expires, when the account expires, and the minimum and maximum number of days between changes. A one-line status comes from sudo passwd -S deploy; its format differs between distributions, but it tells you whether the password is set, locked, or empty.

CommandEffect
sudo chage -M 90 deployPassword valid for 90 days
sudo chage -m 1 deployAt least one day between changes
sudo chage -W 7 deployWarning 7 days before expiry
sudo chage -E 2027-06-30 deployAccount expires on that date

Lock and Unlock a Password

sudo passwd -l deploy
sudo passwd -u deploy

Locking puts an exclamation mark in front of the stored password hash, so no typed password can match it. It does not close other ways in: a user with an SSH key in authorized_keys can still log in. To block the account completely, expire it as well:

sudo usermod -L -e 1 deploy

To open it again, run sudo usermod -U -e "" deploy, which unlocks the password and removes the expiry date.

Set Passwords in a Script with chpasswd

passwd is interactive. chpasswd reads lines in the form user:password from standard input, which suits scripts and changes to several accounts. Do not put the password into the command itself, for example after echo: the whole line is saved in your shell history (see the history command). Feed it through standard input instead. Run chpasswd and type the line, then press Ctrl+D:

sudo chpasswd
deploy:STRONG_PASSWORD

In a script, read the password without echoing it and pass it through a pipe. printf is built into the shell, so the password does not appear in the process list either:

read -rs NEWPASS
printf 'deploy:%s\n' "$NEWPASS" | sudo chpasswd
unset NEWPASS

For many accounts, write the lines to a file that only root can read, run sudo sh -c 'chpasswd < /root/passwords.txt', and delete the file afterward.

When the Change Fails

  • The new password is refused: it breaks the local quality rules. Choose a longer one; a passphrase of several words is easier to remember.
  • An authentication token error: the system could not write the password file. Common causes are a full disk and a root file system that has turned read-only; see read-only file system.
  • The user does not exist: check the exact name with how to list users in Linux.
  • SSH still refuses the new password: password login may be turned off in the SSH server, which is a good setting. Log in with a key instead; see how to generate SSH keys.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations