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.
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
rootorsudoprivileges 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:
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:
sudo passwd rootIf you are already logged in as root:
passwdEnter the new password, then confirm it. Nothing is displayed while you type, which is normal. The success message depends on the system:
passwd: password updated successfullyOn Rocky Linux 9, you will see this instead:
passwd: all authentication tokens updated successfully.Change a user's password
For your own account, the system first asks for the current password:
passwdFor another account, with administrator privileges:
sudo passwd YOUR_USERForce a change at next login
This command is useful when you give someone a temporary password:
sudo chage -d 0 YOUR_USERChange 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:
read -rs -p 'New password: ' MDP; echo
printf '%s:%s\n' YOUR_USER "$MDP" | sudo chpasswd
unset MDPGenerate a strong password
openssl rand -base64 24Store the result in a password manager. Use a different password for each server and each account.
Check the change
1. Check the account status:
sudo passwd -S YOUR_USERYOUR_USER P 2026-11-18 0 99999 7 -1The 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:
sudo chage -l YOUR_USER3. Test the login from a second terminal, without closing the first one. These options force SSH to use the password rather than a key:
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no YOUR_USER@SERVER_IP4. If this account uses sudo, check that it accepts the new password:
sudo -k
sudo -vIf 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:
loginctl list-sessions
sudo loginctl terminate-session SESSION_NUMBERLook for the authorized keys on the server and remove any you do not know:
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
sudo passwd -l YOUR_USER # lock the password
sudo passwd -u YOUR_USER # unlock itLocking 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:
sudo usermod --expiredate 1 YOUR_USER
sudo usermod --expiredate '' YOUR_USERForgotten password
You still have access
If an SSH key or another session still works, simply set a new password:
sudo passwd rootIf 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.
-
In your client area, open your instance. In Vue générale (Overview), click Image ISO, then Ajoutez un ISO (Add an ISO).
-
In Télécharger l'URL (Download URL), paste the link to a standalone Linux image. You can choose the file ending in
-standard.isofrom the official Debian Live images folder. -
Once the ISO has been downloaded, open the menu on its row, choose Monter (Mount), then restart the VPS.
-
Click Accéder à la console VNC (Access the VNC console), then NoVNC Console graphique (NoVNC graphical console).
-
In the standalone system, switch to
rootand locate your system partition:Terminalsudo -i lsblk -f -
Mount this partition, adapting its name (
/dev/vda1is only an example), then check that it is the right one:Terminalmount /dev/vda1 /mnt ls /mnt/etc/shadowIf
/mnt/etc/shadowdoes not exist, unmount withumount /mntand try another partition. If the system uses LVM, first activate the volumes withvgchange -ay, then mount the root volume shown bylsblk. -
Change the password:
Terminalchroot /mnt passwd root -
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:
Terminaltouch /mnt/.autorelabel -
Unmount the partition and shut down the standalone system:
Terminalumount /mnt poweroff -
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:
findmnt -no OPTIONS /
df -h /etc
df -i /etc
lsattr /etc/passwd /etc/shadowroat the start of the options indicates a read-only filesystem. Checksudo dmesg | tail -n 30before going any further.- A disk or inodes at 100% prevent writing. See Check Disk Space and Usage in Linux.
- An
iin thelsattroutput 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:
sudo chage -m 0 YOUR_USERYou 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:
getent passwd YOUR_USERSSH 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 forrootwithprohibit-password.
Check the configuration, including the files in /etc/ssh/sshd_config.d/:
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:
sudo sshd -t
sudo systemctl reload ssh # Debian, Ubuntu
sudo systemctl reload sshd # Rocky Linux, AlmaLinuxYOUR_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:
usermod -aG sudo YOUR_USER # Debian, Ubuntu
usermod -aG wheel YOUR_USER # Rocky Linux, AlmaLinuxReferences
- Manual pages:
man passwd,man chage,man chpasswd,man sshd_config - passwd(1) on Debian
- sshd_config(5) on Debian
- Resetting the root password on RHEL, with which Rocky Linux and AlmaLinux are compatible