Learning Linux

Recover root password

Haz click aquí para leer en Español

Disclaimer: Running rm -rf / on your computer will free up some space (Please do not do it)

Let’s work with Linux! I have been working with Linux for some time now and to be honest, it is the best Operating System (OS), being open source, reliable, backed up by a large community and much more! Let me show you how to change root password Linux, with some simple Linux commands.

As you might know, Linux server is free and easy to install. Thanks to my amazing colleagues, we need to change root password Linux more often than you think. PS: I hope my teammates know I am joking!

For this post, the linux distribution in use is CentOS8:

uname -r && cat /etc/redhat-release
Kernel and Linux distro

Recover root password | Change root password Linux

  • Restart your computer (reboot command)
  • Edit grub (press e when booting) and remove the ro (read-only)  → rescue mode
Grub config before

Add this instead of ro –> rw init=/sysroot/bin/sh 

Grub config after

Press ctrl x to start. The above will initialize your PC in single user mode.

Then, you would need to run these simple Linux commands:

  • chroot /sysroot → To mount the filesystem to sysroot
  • passwd root →  To change root password

Before exiting update SELinux information by running the following command:

  • touch /.autorelabel
  • exit
  • reboot
Linux commands

You can omit the warnings of BAD PASSWORD from the image above.

SELinux do not complain

After a bit of waiting, you should see your prompt.

ERROR: Failed to start user manager for UID 42 → Related to SElinux (you might have miss touch /.autorelabel)

What is chroot use for?

It is used to change the apparent root directory for the current running process and their children. Changing root is commonly done for performing system maintenance on systems where booting and/or logging in is no longer possible. Common examples are:

  • Reinstalling the bootloader
  • Rebuilding the initramfs image
  • Resetting a forgotten password
Is Linux an operating system?

Yes, just like Microsoft Windows, macOS, iOS, Android, just to name a few.

Is it possible to recover ubuntu root password?

Yes, you can recover the root password of the different Linux distros.

As you can see, it is an easy task that we all should be aware of!

Easy to play

For my following entries, I will write about SELinux, bootloader, initramfs, handy tools to work in Linux and more. Stay tuned and follow the blog!

If you have time, check my other posts and let me know if you have done something similar.


More resources:

If you want to know about Apache click here

If you want to know more about finances and investment here

If you want to know about Ansible here

7 thoughts on “Learning Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: