How to change root and user password on Linux VPS
The passwd command allows you to change the password of the current account, root or another user. Make the change over a secure connection and do not share the new password.
Change current user password
passwd
Enter your current password when prompted and enter the new password twice.
Change another user's password
An account with sudo can run:
sudo passwd NOME_DO_USUARIO
Replace with the correct user. The system will ask for the new password, without displaying the characters.
Change root password
If you already have sudo:
sudo passwd root
This sets a password for the root account, but does not automatically enable SSH root login when it is locked in configuration.
For administrative tasks, prefer an individual account with sudo.
Create a strong password
Use:
- high length;
- unpredictable combination of words or characters;
- exclusive password for the VPS;
- password manager;
- no personal information or service name.
Do not reuse the password for email, financial dashboard or other servers.
Check when password was changed
sudo chage -l NOME_DO_USUARIO
The command shows the last change and expiration rules for the account.
Force switch on next login
sudo chage -d 0 NOME_DO_USUARIO
Use this when creating a temporary password for someone else. Confirm beforehand that the access flow allows the switch.
Lock and unlock password
Block:
sudo passwd -l NOME_DO_USUARIO
Unlock:
sudo passwd -u NOME_DO_USUARIO
Locking the password does not terminate already open sessions and may not prevent other authentication methods, such as an SSH key.
Forgot VPS password
If no sudo account is available, recovery depends on the environment's administrative features, such as console, recovery mode, or reinstallation.
Before changing system files:
- confirm the correct user;
- consult the panel features;
- preserve data;
- avoid recovery tutorials intended for another distribution;
- open a ticket when in doubt.
Password has been changed, but SSH does not accept it
Check it out:
- whether password login is enabled;
- if the account is blocked;
- if the username was entered correctly;
- whether SSH uses another port;
- logs with journalctl -u ssh;
- whether authentication requires a key.
Frequently asked questions
Does changing the password disconnect open sessions?
Normally not. Existing sessions continue until closed.
Can I use only SSH key?
Yes, after testing the key. Disabling passwords before testing may block access.
How to create a separate administrative account?
See how to create a sudo user on Ubuntu VPS.
If you need help, open a ticket with Nice Hosting support.