How to Change Root Password in Ubuntu Linux
Learn how to change root password in ubuntu linux using sudo passwd root, and how to reset a forgotten root password via GRUB single-user recovery mode.

6 min read
Learn how to change root password in ubuntu linux using sudo passwd root, and how to reset a forgotten root password via GRUB single-user recovery mode.
- Prerequisites and Supported Releases
- Method 1: Changing the Root Password Using Sudo (When Sudo is Working)
- Method 2: Resetting a Forgotten Root Password via GRUB Recovery Mode
The root superuser account represents the apex authority in any Linux operating system, maintaining unrestricted power over filesystems, kernel configurations, and security policies.
Ubuntu approaches root account security differently than traditional distributions: upon installation, the root account password is locked with an invalid hash (!) to prevent direct password logins.
However, system administrators may occasionally need to assign a dedicated root password for single-user emergency maintenance or specialized deployment scripts.
Furthermore, when administrative sudo access is lost or root credentials are forgotten, knowing how to recover and reset the root password through system recovery mechanisms is critical.
In this guide, we explain how to change root password in ubuntu linux when you have existing sudo access, and how to recover root access through GRUB boot parameters when credentials are lost.
Comprehensive Linux disaster recovery and administrator tutorial on modifying and resetting the root superuser password on Ubuntu 24.04 LTS (Noble Numbat) and 22.04 LTS. Covers standard password modification via sudo passwd root, resetting forgotten credentials via GRUB boot parameter editing (init=/bin/bash), and locking the root account after maintenance.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A server, virtual machine, or workstation running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- An active sudoer user account (for Method 1).
- Physical or virtual console access (KVM/VNC) to interact with the GRUB bootloader menu (for Method 2).
- Basic familiarity with Linux terminal commands and filesystem remounting.
Method 1: Changing the Root Password Using Sudo (When Sudo is Working)
If you currently have access to a non-root user account that belongs to the sudo group, changing the root password requires only a single command.
Invoke passwd root prepended with sudo:
Ubuntu prompts you for your personal user password to verify administrative authority, then prompts you to enter and confirm the new root password:
# Update or set the root user password:
sudo passwd root
# Terminal interactive prompt flow:
# [sudo] password for your_user: [Enter your current password]
# New password: [Enter desired root password]
# Retype new password: [Confirm desired root password]
# passwd: password updated successfully
# Test the new root password using su:
su -
# Enter the newly configured root password.
# Verify identity:
whoami
# Output: root
Method 2: Resetting a Forgotten Root Password via GRUB Recovery Mode
If you do not have a working sudo user and the root password is unknown or forgotten, you must reset credentials through the GRUB bootloader.
This disaster recovery procedure bypasses normal user authentication by instructing the Linux kernel to initialize an emergency root shell directly.
Restart your machine and access the GRUB boot menu by holding Shift (on BIOS systems) or tapping Escape (on UEFI systems):
Follow these precise recovery steps:
Step 2.1: Editing GRUB Kernel Boot Parameters
In the GRUB selection menu, highlight the default Ubuntu entry and press the e key to edit boot parameters.
Use the arrow keys to scroll down to the line beginning with linux (which loads the kernel binary):
Navigate to the end of that line, remove ro quiet splash, and append rw init=/bin/bash:
# Original GRUB line snippet:
# linux /boot/vmlinuz-6.8.0-31-generic root=UUID=... ro quiet splash $vt_handoff
# Modified GRUB line snippet:
# linux /boot/vmlinuz-6.8.0-31-generic root=UUID=... rw init=/bin/bash
# Press Ctrl+X or F10 to boot with these temporary parameters.
Step 2.2: Resetting the Password in the Root Emergency Shell
The system boots directly into an unauthenticated root bash prompt (root@(none):/#).
Verify that the root filesystem is mounted with read-write (rw) permissions:
Reset the root password using the passwd command, then reboot the machine cleanly:
# Verify filesystem is mounted read-write:
mount -o remount,rw /
# Reset root password:
passwd root
# Enter new root password twice.
# Force filesystem synchronization to disk:
sync
# Reboot system using kernel reboot trigger:
reboot -f
Step 3: Restoring Ubuntu's Default Security Posture (Locking Root)
Having an active password on the root account exposes remote servers to automated brute-force attacks against the 'root' login name.
Once emergency recovery or specialized administration is finished, best practice is to re-lock the root account:
Use passwd -l to disable password logins while retaining sudo privileges for your administrative user:
# Re-lock the root user account password:
sudo passwd -l root
# Output: passwd: password expiry information changed.
# Confirm that /etc/shadow reflects the locked status (prepended with !):
sudo grep '^root:' /etc/shadow
# Output: root:!$y$j9T$...
Comparison of Root Password States in Ubuntu
Understand the operational impact of different root account states on Ubuntu:
| Root State | Shadow File Indicator | Can Login with Password? | Can Login via SSH Keys? | Recommended Environment |
|---|---|---|---|---|
| Default (Locked) | root:!:... | No (Rejected immediately) | Yes (If public key in /root/.ssh/authorized_keys) | Production servers (Standard Ubuntu posture) |
| Enabled (Password Set) | root:$y$... | Yes (via su - or console login) | Yes | Temporary rescue or legacy software maintenance |
| Locked after Password Set | root:!$y$... | No (Password temporarily locked) | Yes | Post-maintenance secured state |
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
passwd: Authentication token manipulation error during GRUB recovery
Cause: The root filesystem is mounted read-only (ro).
Resolution: Remount the root filesystem with write permissions using mount -o remount,rw / before running passwd.
mount -o remount,rw / && passwd root
GRUB menu does not appear on boot (boots straight to login screen)
Cause: GRUB timeout is set to 0 and menu is hidden by default.
Resolution: Continuously tap Escape on UEFI hardware or hold Shift on BIOS hardware immediately after powering on the computer.
cat /etc/default/grub | grep GRUB_TIMEOUT
Terminal hangs when typing 'reboot' in emergency bash shell
Cause: init=/bin/bash replaces systemd, so standard systemctl shutdown scripts are unavailable.
Resolution: Run sync to flush buffers to disk, then trigger an immediate hardware reboot using reboot -f.
sync && reboot -f
Security Best Practices and Hardening
To prevent physical attackers from resetting the root password via GRUB parameters, protect your GRUB bootloader with a password (grub-mkpasswd-pbkdf2).
Enable full-disk encryption (LUKS) on laptop and workstation installations to prevent unauthenticated data access via recovery kernels.
Disable direct SSH root login by setting PermitRootLogin no in /etc/ssh/sshd_config.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Enable and Disable Root User Account in Ubuntu — Explore the security philosophy behind Ubuntu's locked root account.
- How to Change User Password in Ubuntu — Manage standard user credentials, password policies, and aging.
- How to Add a User to Sudoers in Ubuntu — Configure administrative sudo rights to manage servers securely.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
!) in /etc/shadow, meaning no password string can authenticate directly until an administrator explicitly creates one.sudo passwd root sets an active password for the root superuser. sudo passwd -l root locks the password by prepending an exclamation mark, preventing password-based root logins while preserving sudo functionality./etc/shadow; all user files, service configurations, and installed applications remain completely intact.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!