Website Vidya
SecurityStep-by-Step Guide

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.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Change Root Password in Ubuntu Linux
AI Executive SummaryWebsiteVidya AI

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.

Key Highlights
  • 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
Grounded in full engineering runbookWebsiteVidya AI Engine

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.

Advertisement

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.

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:

Advertisement
  • 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.

Advertisement

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 StateShadow File IndicatorCan 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)YesTemporary rescue or legacy software maintenance
Locked after Password Setroot:!$y$...No (Password temporarily locked)YesPost-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.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
No. Ubuntu does not ship with a default root password. The root account is created with an invalid password hash (!) in /etc/shadow, meaning no password string can authenticate directly until an administrator explicitly creates one.
Yes. Anyone with unencrypted physical access to the hardware can edit GRUB boot arguments to launch a root shell, unless the GRUB menu is password-protected and the storage drive is encrypted using LUKS full-disk encryption.
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.
No. Resetting the root password only updates the encrypted hash string in /etc/shadow; all user files, service configurations, and installed applications remain completely intact.
RR
Written byVerified Author

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.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout