What this is
This procedure changes the password of the root user on a Linux server.
What it is for
- Regain access when you need to update credentials
- Improve security by rotating the root password
- Prepare the server before handing it to another admin
Prerequisites
- SSH access to the server
- You must be logged in as
rootor as a user withsudoprivileges
Step-by-step (extremely detailed)
Step 1) Confirm who you are logged in as
Command:
whoami
What it does: Prints the current username.
Why it is needed: You must know if you need sudo.
Expected output: root or your username (example: ubuntu).
Step 2) Change the root password
Option A (you are root)
Command:
passwd
What it does: Changes the password for the current user (root).
Why it is needed: This is the standard, safe way to change passwords.
What you should expect: Prompts like:
New password:
Retype new password:
passwd: password updated successfully
Important note: When typing passwords, Linux does not show characters on screen.
Option B (you are NOT root, but you have sudo)
Command:
sudo passwd root
What it does: Changes the password of the root user.
Why it is needed: Allows an admin user to reset root password.
Expected output: Similar prompts to Option A, ending with password updated successfully.
Step 3) (Recommended) Make sure root password login is not your only access
Why this matters: If you lose the root password and have no sudo user or SSH key, you can lock yourself out.
Quick check: Ensure you have at least one sudo user and SSH access still works.
Warnings & useful notes
- Use a strong password (long, unique, not reused).
- Do not paste passwords into chats or tickets.
- If you use SSH keys and have disabled password auth, changing root password may not affect your SSH login (and that is OK).
Final verification
Verify sudo/root still works
Command (if you are a sudo user):
sudo -v
Expected output: Usually silent on success (or asks for your password then succeeds).
Conclusion
You successfully changed the root password. As a best practice, keep at least one additional sudo user and prefer SSH keys for login.