Categories: Linux Administration

How To Reset Your Root Password On CentOS 7 Servers

This tutorial is going to show you a simple trick that you can use to reset your forgotten root password for CentOS 7 servers. Sometimes things happen and you totally forget your password. It happens to the best of us.

This tutorial will only work if you have direct access to the machine (example: You are next to the machine or have KVM/IPMI)

You can’t reset the root password if you’re remotely connected since you need boot menu access.

If you have a ServerHub Bare Metal Server this shouldn’t be an issue as we offer IPMI completely free with every server we sell.

To get started, turn on the machine that you’ve forgotten the root password on. For CentOS 7 devices, you’ll be given 5 seconds at the boot menu to select the operating system kernel to boot into.

That 5 seconds is important, because allows for  admins to select different kernels or edit existing kernel parameters before booting.

At the boot menu, press e to edit the existing kernel (Core)

Next, scroll down to the list until you see the line underlined below ( ro ) . What we need to do is change that ro to rw and start into a bash shell. It should look like this rw init=/sysroot/bin/sh.

Change the ro line to rw and add init=/sysroot/bin/sh

rw init=/sysroot/bin/sh

After changing that, press Control + X  or Ctrl + X  on your keyboard to start into single user mode using the bash shell specified above. In this mode, we’re going to change the root password.

In the single user mode, run the command as shown below

chroot /sysroot

Finally, run the commands below to change the root password.

You’ll be prompted to create and confirm a new password.  After creating the password, run the commands below to update SELinux parameters

touch /.autorelabel

Exit and reboot your system. Your password should now be successfully reset!


serverhub

Recent Posts

Unlocking the Power of Splunk: A Comprehensive Guide

Splunk is a cutting-edge data analytics platform designed to search, monitor, and analyze machine-generated data…

2 weeks ago

Oracle Database: In-Depth Guide & FAQs (Simple, Clear and Includes “FAQs”)

What is Oracle Database? Oracle Database is a powerful, multi-model database management system developed by…

1 month ago

Fail2Ban: Protect Your Linux System from Brute-Force Attacks – Open-Source Security Tool

Fail2Ban is an intrusion prevention software framework, written in the Python programming language. It is…

1 month ago

ISPConfig: The Open-Source Control Panel for Effortless Web Hosting Management

ISPConfig is an open-source hosting control panel for managing web hosting services. It provides a…

2 months ago

FirewallD: Dynamic Firewall Manager – A ServerHub Comprehensive Guide

Firewalld is a dynamic firewall management tool for Linux systems that simplifies network traffic control…

2 months ago

Learn About Let’s Encrypt: A Free SSL/TLS Certificate Provider

Let's Encrypt is a nonprofit certificate authority offering free, automated, and open digital certificates for…

3 months ago

This website uses cookies.