EN

Linux and networking

Change the root or a user password over SSH

Change the root or a Linux user password over SSH on Debian, Ubuntu, Rocky Linux and AlmaLinux, test it without losing access, and recover a forgotten password.

8 min read, updated on 18 November 2026

On this page

Your values

Enter them once and the commands in this guide update.

This guide explains how to change the password of root or another user from an SSH session, check that the new password works, and what to do if you have lost it. The commands apply to Debian, Ubuntu, Rocky Linux and AlmaLinux.

Prerequisites

  • SSH access to your server
  • root or sudo privileges to change another account's password
  • The current password, if you are changing your own without sudo

In the commands, replace YOUR_USER with the name of the account concerned and SERVER_IP with your server's address.

Check how you log in

A password is only useful over SSH if the server allows it. First, look at the configuration actually in effect:

Terminal
sudo sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication) '
Displayed value What it means
permitrootlogin yes root can log in over SSH with its password
permitrootlogin without-password or prohibit-password root can log in over SSH only with a key. Its password is still useful for su and the VNC console
permitrootlogin no root cannot log in directly over SSH
passwordauthentication yes Allowed accounts can use a password over SSH
passwordauthentication no Only SSH keys are accepted, whatever the password

Change the root password

From an account with sudo:

Terminal
sudo passwd root

If you are already logged in as root:

Terminal
passwd

Enter the new password, then confirm it. Nothing is displayed while you type, which is normal. The success message depends on the system:

Text
passwd: password updated successfully

On Rocky Linux 9, you will see this instead:

Text
passwd: all authentication tokens updated successfully.

Change a user's password

For your own account, the system first asks for the current password:

Terminal
passwd

For another account, with administrator privileges:

Terminal
sudo passwd YOUR_USER

Force a change at next login

This command is useful when you give someone a temporary password:

Terminal
sudo chage -d 0 YOUR_USER

Change a password in a script

chpasswd reads lines in the form user:password. To keep the password out of your shell history, prompt for it with read:

Terminal
read -rs -p 'New password: ' MDP; echo
printf '%s:%s\n' YOUR_USER "$MDP" | sudo chpasswd
unset MDP

Generate a strong password

Terminal
openssl rand -base64 24

Store the result in a password manager. Use a different password for each server and each account.

Check the change

1. Check the account status:

Terminal
sudo passwd -S YOUR_USER
Text
YOUR_USER P 2026-11-18 0 99999 7 -1

The second field shows the password status, and the third the date of the last change.

Code Meaning
P or PS A usable password is set
L or LK The password is locked
NP The account has no password

2. View the expiry dates:

Terminal
sudo chage -l YOUR_USER

3. Test the login from a second terminal, without closing the first one. These options force SSH to use the password rather than a key:

Terminal
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no YOUR_USER@SERVER_IP

4. If this account uses sudo, check that it accepts the new password:

Terminal
sudo -k
sudo -v

If sudo -v returns without an error, everything is in order. You can then close the old session.

After suspicious access

Changing a password does not close open sessions and does not revoke SSH keys. If you think an account has been compromised, check these two points as well.

List the sessions, then terminate any you do not recognize:

Terminal
loginctl list-sessions
sudo loginctl terminate-session SESSION_NUMBER

Look for the authorized keys on the server and remove any you do not know:

Terminal
sudo find /root /home -name authorized_keys -type f -exec ls -l {} \; -exec cat {} \;

If a compromise is likely, changing the password is not enough: back up your data and consider reinstalling the server.

Lock or disable an account

Terminal
sudo passwd -l YOUR_USER   # lock the password
sudo passwd -u YOUR_USER   # unlock it

Locking only blocks the password: an SSH key keeps working. To disable the account completely, make it expire, then remove the expiry to re-enable it:

Terminal
sudo usermod --expiredate 1 YOUR_USER
sudo usermod --expiredate '' YOUR_USER

Forgotten password

You still have access

If an SSH key or another session still works, simply set a new password:

Terminal
sudo passwd root

If sudo asks for the password you forgot, log in with an account that can still use it, or directly as root with a key, then run passwd YOUR_USER.

You no longer have any access

You can boot the VPS on a standalone Linux system, then change the password from there. This method uses the Image ISO (ISO image) section and the VNC console of your client area, described in the guide Back up your VPS with Clonezilla.

  1. In your client area, open your instance. In Vue générale (Overview), click Image ISO, then Ajoutez un ISO (Add an ISO).

  2. In Télécharger l'URL (Download URL), paste the link to a standalone Linux image. You can choose the file ending in -standard.iso from the official Debian Live images folder.

  3. Once the ISO has been downloaded, open the menu on its row, choose Monter (Mount), then restart the VPS.

  4. Click Accéder à la console VNC (Access the VNC console), then NoVNC Console graphique (NoVNC graphical console).

  5. In the standalone system, switch to root and locate your system partition:

    Terminal
    sudo -i
    lsblk -f
  6. Mount this partition, adapting its name (/dev/vda1 is only an example), then check that it is the right one:

    Terminal
    mount /dev/vda1 /mnt
    ls /mnt/etc/shadow

    If /mnt/etc/shadow does not exist, unmount with umount /mnt and try another partition. If the system uses LVM, first activate the volumes with vgchange -ay, then mount the root volume shown by lsblk.

  7. Change the password:

    Terminal
    chroot /mnt passwd root
  8. On Rocky Linux and AlmaLinux only, request that the SELinux contexts be restored. Without this, logging in may fail after the restart. The next boot will take longer:

    Terminal
    touch /mnt/.autorelabel
  9. Unmount the partition and shut down the standalone system:

    Terminal
    umount /mnt
    poweroff
  10. In Image ISO, open the menu on the row, choose Démonter (Unmount), then restart the VPS from your client area.

If you would rather not work on the disk yourself, open a ticket with support from your client area.

Troubleshooting

passwd: Authentication token manipulation error

The change was refused. The current password you entered may be wrong. Otherwise, check that the system can write to its account files:

Terminal
findmnt -no OPTIONS /
df -h /etc
df -i /etc
lsattr /etc/passwd /etc/shadow
  • ro at the start of the options indicates a read-only filesystem. Check sudo dmesg | tail -n 30 before going any further.
  • A disk or inodes at 100% prevent writing. See Check Disk Space and Usage in Linux.
  • An i in the lsattr output means the file is immutable. If you did not set this attribute yourself, treat it as a possible sign of compromise.

BAD PASSWORD: The password is shorter than 8 characters

The password policy considers your choice too weak. A regular user must pick another one. root can override this warning, but it is better to choose a strong password.

Sorry, passwords do not match.

The two entries differ. Run the command again. In the VNC console, also check the keyboard layout: an AZERTY keyboard interpreted as QWERTY changes several characters.

You must wait longer to change your password

The account enforces a minimum delay between two changes. View it with sudo chage -l YOUR_USER. An administrator can change the password with sudo passwd YOUR_USER or remove this delay:

Terminal
sudo chage -m 0 YOUR_USER

You may not view or modify password information for root.

On Rocky Linux 9, the equivalent message is Only root can specify a user name. You are trying to change another account without sufficient privileges. Add sudo in front of the command.

user 'name' does not exist or Unknown user name

Check the spelling of the account:

Terminal
getent passwd YOUR_USER

SSH rejects the new password

  • Permission denied (publickey).: the server does not accept passwords. Log in with your key.
  • Permission denied, please try again.: the password is incorrect, or this account cannot log in this way. This is the case for root with prohibit-password.

Check the configuration, including the files in /etc/ssh/sshd_config.d/:

Terminal
sudo sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication) '
sudo grep -RniE '^(PermitRootLogin|PasswordAuthentication)' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

If you change this setting, validate the file before reloading the service, from a session that stays open:

Terminal
sudo sshd -t
sudo systemctl reload ssh    # Debian, Ubuntu
sudo systemctl reload sshd   # Rocky Linux, AlmaLinux

YOUR_USER is not in the sudoers file

The account is not allowed to use sudo. As root, add it to the appropriate group, then have it log in again:

Terminal
usermod -aG sudo YOUR_USER    # Debian, Ubuntu
usermod -aG wheel YOUR_USER   # Rocky Linux, AlmaLinux

References