Managing root-level credentials is a critical part of Linux server security. Whether you are onboarding new administrators, rotating privileged credentials, or implementing security policies, updating the root password must be performed carefully using proper system tools and authentication controls.
This guide explains how to safely change the root password on the most common Linux distributions, including:
- RHEL 8 / 9
- AlmaLinux 8 / 9
- Rocky Linux 8 / 9
- Ubuntu 20.04 / 22.04 / 24.04
- Debian 11 / 12
Method 1 – Change the Root Password on RHEL / AlmaLinux / Rocky Linux
This method applies to all RHEL-based systems, including AlmaLinux and Rocky Linux.
Step 1 — Log in as root or use sudo
sudo -iThis command elevates your session to root privileges using sudo.
Step 2 — Change the root password
passwdThe system will prompt you to type the new root password twice.
Changing password for user root.
New password:
Retype new password:Step 3 — Confirm the password change
passwd -S rootThis outputs the current password status of the root account.
Method 2 – Change the Root Password on Debian / Ubuntu
Debian and Ubuntu behave slightly differently, especially because Ubuntu keeps the root account locked by default.
Step 1 — Switch to root using sudo
sudo -iThis grants administrative privileges necessary to modify account passwords.
Step 2 — Change the root password
passwd rootProvide the new root password twice when prompted.
Enter new UNIX password:
Retype new UNIX password:If the root account is locked (Ubuntu default)
Enable the root account by assigning it a password:
sudo passwd rootTo disable the root account again later:
sudo passwd -l rootBest Practices After Changing the Root Password
- Update your team’s password vault or secret management system (Bitwarden, Keeper, Vault, etc.)
- Disable direct root login over SSH by setting
PermitRootLogin no - Use sudo for daily administration instead of root
- Rotate privileged passwords regularly to comply with security policies
- Restrict SSH access by IP and enable MFA whenever possible
Conclusion
Updating the root password is a simple but essential part of maintaining a secure Linux environment. Whether you manage RHEL-based servers such as AlmaLinux and Rocky Linux or Debian-based systems like Ubuntu and Debian, the passwd command remains the most reliable method for modifying privileged credentials.
By following the steps in this guide and applying the recommended security best practices, your Linux server will remain compliant, secure, and ready for production workloads.





