How to Change the Root Password on Ubuntu
To change the root password on Ubuntu or Debian, log in as root and run passwd; if you are logged in as a regular user, run sudo passwd root. You will be asked for the new password twice, and nothing is shown while you type. This guide shows how to change root password Ubuntu servers use safely, how to generate a strong one, what to do if it is lost, and how to drop password logins altogether.
Step 1. Connect to Your Server
Open a terminal on the server as root. On 0x.cloud, that is the web console on the server page in your dashboard: log in there with the root password shown on the same page. With other providers, the current root password is usually shown in their dashboard, and you connect with ssh root@SERVER_IP.
Step 2. Change the Root Password on Ubuntu or Debian
Logged in as root:
passwd
Logged in as a sudo user:
sudo passwd root
sudo asks for your own password first, then passwd asks for the new root password twice. On success you will see:
passwd: password updated successfully
On Debian 12 without sudo, switch to root with su - and run passwd. All options are in man passwd.
Step 3. Test the New Password
If you are connected over SSH, keep the current session open, open a second terminal window and log in again with ssh root@SERVER_IP. In the 0x.cloud web console, log out with exit and log in again with the new password; if that fails, reset the root password in your dashboard.
If it works, you are done. If not, the open session lets you fix it.
Generate a Strong Password
Bots try root passwords on every internet-facing server around the clock. Use a long random password:
# generate a random 24-character password
openssl rand -base64 24
Store it in a password manager and never reuse it elsewhere.
Change the Root Password in a Script
For automation (say, an AI agent provisioning a server), use chpasswd:
# set the password without prompts
echo 'root:A-Long-New-Password' | sudo chpasswd
The command lands in shell history. Remove it (history -d with the line number) or read the password from a file.
You can also have an AI agent generate and set the password:
Connect to my server as root over SSH or through the 0x.cloud MCP. Generate a random 24-character password with openssl rand -base64 24 and set it for root with chpasswd so the password never lands in shell history or logs. Show me the password once, then check the status with passwd -S root.
Forgot the Root Password?
| Situation | What to do |
|---|---|
| You can log in as root with an SSH key | log in and run passwd |
| You have a sudo user | log in as that user and run sudo passwd root |
| Password login only, and the password is lost | on 0x.cloud, reset the root password on the server page in your dashboard (the server must be running); elsewhere use the provider's console (recovery mode) or reinstall the OS |
To make a lost password a non-event, set up key login: how to add an SSH key.
Even Safer: No Root Password Logins
A new password protects you until it leaks. A sturdier setup takes three steps:
- Create a regular user with sudo rights: add a sudo user on Ubuntu.
- Set up SSH key login.
- Turn off password authentication: disable SSH password login.
Then you can lock the root password entirely. Key login and sudo keep working:
# lock the root password
sudo passwd -l root
# check status: L means locked, P means a password is set
sudo passwd -S root
Unlock with sudo passwd -u root.
Errors and Fixes
| Error | Cause | Fix |
|---|---|---|
passwd: Authentication token manipulation error |
read-only filesystem or no access to /etc/shadow |
check mount | grep ' / ' and df -h; free up disk space |
BAD PASSWORD: The password is shorter than 8 characters or You must choose a longer password |
password quality rules | use a longer password; root can override, but should not |
Sorry, passwords do not match |
the two entries differ | run the command again carefully |
is not in the sudoers file |
your user lacks sudo rights | log in as root or add the user to the sudo group |
| SSH login fails after the change | root password login is disabled (PermitRootLogin prohibit-password) |
log in with a key or as a sudo user |
Practice SSH hardening on a separate box so you never risk production: s1-1 on hourly billing is about $0.030750 an hour, and deleting it returns the unused amount to your balance. See VPS pricing.
FAQ
What is the default root password on Ubuntu? On Ubuntu Desktop, root has no password: the account is locked and admin rights come from sudo. On a VPS, the provider usually sets a root password when the server is created and shows it in the dashboard.
How do I change the root password from a regular user? Run sudo passwd root, enter your own user's password, then the new root password twice. Your user must be in the sudo group.
What if I forgot the root password? If you can log in with an SSH key or as a sudo user, do that and set a new password with passwd. With no access at all, reset it in the provider's dashboard (on 0x.cloud, on the server page), use the provider's console (recovery mode) or reinstall the OS.
Will changing the password drop my SSH sessions? No. Open sessions keep working; the new password applies to the next login.
Can I change the root password in a script? Yes: echo 'root:NewPassword' | sudo chpasswd. The password ends up in shell history, so use passwd for interactive work.