21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Blog · WebJi® India

How to Change the Root Password in Linux

Quick answer

To change the root password in Linux, run passwd as root, or sudo passwd root from a sudo user, and type the new password twice; it works immediately without a reboot. If the password is lost, set a new one from a rescue console or a GRUB root shell, then check SSH keys and PermitRootLogin.

For VPS and dedicated server administrators who need to change, reset or lock down the root account on Ubuntu, Debian or RHEL-family Linux.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
6 min
Sections
8
Updated
14 Nov 2026
Written by
WebJi® team

How do you change the root password in Linux?

Logged in as root, run passwd; from a user with sudo rights, run sudo passwd root; then type the new password twice and it takes effect immediately, with no reboot. Nothing appears on screen while you type, which is normal.

# As root
passwd

# As a sudo user
sudo passwd root

# Check the account's password status afterwards
sudo passwd -S root

If the new password is rejected, it failed the system's quality rules (usually pam_pwquality); a longer passphrase passes more easily than a short one full of symbols. On Ubuntu the root account is locked by default, and sudo passwd root sets a password for it — only do this if you actually need direct root logins.

When should you change the root password?

Change the root password when someone who knew it leaves, when it may have been exposed, before handing a server over, and right after receiving a new server whose password arrived by email. Event-driven changes protect more than a blind calendar rotation.

  • New server: replace the password from the welcome email on first login.
  • Staff or contractor leaves: change it the same day and review sudo users.
  • Suspected exposure: change it, then check last and /var/log/auth.log (or journalctl -u sshd) for logins you do not recognise.
  • Handover or sale: change it after the new owner takes over.

How do you change another user's password?

Root or any sudo user can run sudo passwd username to set a new password without knowing the old one; a user changing their own password runs plain passwd and must enter the current one first.

# Reset another account
sudo passwd deploy

# Force the user to choose a new password at next login
sudo chage -d 0 deploy

# See password ageing details
sudo chage -l deploy

To reset several accounts at once, chpasswd reads user:password pairs from standard input. Pipe them in rather than saving them to a file, and clear them from shell history afterwards. To give a new team member admin rights, follow adding a sudo user on Ubuntu.

How do you reset a forgotten root password on a VPS?

If you still have a working sudo user, simply run sudo passwd root; if not, use your provider's out-of-band console (VNC or rescue mode) to boot a rescue system, mount the server's disk and set a new password. This works without the old password because you are editing the system from outside.

# From a rescue system, after identifying the root partition (e.g. /dev/vda1)
mount /dev/vda1 /mnt
passwd --root /mnt root
umount /mnt
reboot

The --root option tells passwd to work on the mounted system's files instead of the rescue system's. Not every VPS plan includes a console or rescue image, so check with your provider before you need it; WebJi® customers can ask support@webji.services, answered 24/7 in Hindi and English with an average first reply under 60 minutes.

How do you reset the root password from GRUB?

With console access to the boot menu, edit the kernel line to boot straight into a root shell (init=/bin/bash), remount the disk read-write, run passwd, and reboot. A GRUB password, if set, must be known first.

  1. Reboot and open the GRUB menu (hold Shift on BIOS systems, or press Esc on many UEFI systems).
  2. Highlight the default entry and press e.
  3. On the line starting with linux, change ro to rw and add init=/bin/bash at the end.
  4. Press Ctrl-X or F10 to boot.
  5. If the disk is still read-only, run mount -o remount,rw /.
  6. Run passwd and enter the new password twice.
  7. On SELinux systems (RHEL, AlmaLinux, Rocky), run touch /.autorelabel so file labels are fixed on the next boot.
  8. Reboot with exec /sbin/init or reboot -f.

RHEL-family systems also support rd.break: add it to the kernel line, then run mount -o remount,rw /sysroot, chroot /sysroot, passwd, touch /.autorelabel, and exit twice. Debian and Ubuntu offer a Recovery mode entry with a root shell option. Because anyone with console access can do this, physical and console security matter as much as the password.

What should you check after changing the root password?

Check that SSH key logins still work, decide whether root may log in over SSH at all, review who has sudo, and update any scripts that stored the old password. A password change does not affect SSH keys.

  • SSH root login: in /etc/ssh/sshd_config, PermitRootLogin prohibit-password allows root by key only; no blocks it entirely. Reload with sudo systemctl reload ssh (or sshd on RHEL-family systems).
  • Keys instead of passwords: set PasswordAuthentication no once keys work; see generating an SSH key on Ubuntu.
  • Sudo group: remove accounts of people who have left (getent group sudo or wheel).
  • Hard-coded credentials: scripts, cron jobs and backup tools that used the old password.
  • Brute-force protection: add fail2ban so repeated guesses are blocked.

Keep a second SSH session open while editing sshd_config, so a mistake cannot lock you out. A MySQL or phpMyAdmin root password is separate from the Linux root password and must be changed in the database itself.

FAQ

Frequently asked questions

Can I change the root password on shared hosting?

No. Shared hosting gives you a control-panel account, not root, so there is no root password to change. Root access comes with a VPS or dedicated server; a WebJi® KVM VPS starts at ₹499 a month before 18% GST.

Does changing the root password log out other sessions?

No. Existing SSH sessions stay open; the new password applies to the next login. To end other sessions, find them with who and terminate them, or restart the SSH service after making sure you have another way in.

Can the old root password be recovered?

No. Linux stores only a salted hash in /etc/shadow, so the original password cannot be read back. Recovery always means setting a new password, using sudo, a rescue console or GRUB.

Should I disable root login completely?

For most servers, yes over SSH: work through a sudo user and set PermitRootLogin no or prohibit-password. Keep a tested console route first, so one bad edit cannot lock you out.

Reviewed by the WebJi® team, Jaipur, 15 November 2026.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.