In this video, you'll learn about an important procedure, that is recovering a lost root
user password.
That also goes for systems that never had a root user password.
If ever you want to get into emergency or rescue targets for troubleshooting, you need
a root user password.
So let's check out how to do it.
Here is the procedure.
You need to go to the group boot menu when you are booting.
And then you need to find the line that loads the Linux kernel.
And to the end of the line, you add initislavebin slash bash.
That makes it, instead of running systemd, you run a bash shell.
And that's a very minimal environment.
Now once you are in that minimal environment, you can use mount-remount,rw slash.
You need to do that because your root file system, as mounted by the kernel, is still
in a read-only mode.
Once it is in a read-writable mode, you can change your password using passwd.
Then you need to take care of su-linux.
You'll learn later why and what exactly.
But for now, you just need to create the file with the name .autorelabel in the root directory.
You don't do that, nobody can log in anymore.
So things will be worse if you don't do it.
And finally, to get out of there, you need to run systemd again.
But the thing is, as you are in a bash shell spid1, you cannot just run systemd in the
ordinary way because it will become a child of the current bash shell.
Systemd can't be the child of anything.
So you need to remove the bash shell and replace it with systemd.
And that was accomplished by using exec slash uselib systemd system.
Let me show you.
So here we have the grub prompt.
I'm pressing E on my default line that loads the default kernel.
Looking for the line that starts with Linux because that's the line that loads the kernel.
And to the end of the line, I'm adding init is slash bin slash bash.
And then I'm using control X to boot with that option.
So the result is that I'm dropped in a root shell.
And that is good.
Nobody is asking anything.
So next, if I create a file, that doesn't work.
So we need mount minus o remount comma rw on slash to remount the root file system in
a read-writable way.
And then it's already time where we can use passwd for the root user.
You're not prompted for anything.
You can just enter the new password once and once again.
And then it's updated.
But you need touch slash dot auto relabel because of SE Linux.
And then finally, you can use exec slash user slash lib slash systemd slash systemd.
If you think that is too hard to remember, you can also just reset the virtual machine
if you want to.
That will also do it.
So now systemd is started.
So now systemd is started, you will see some messages about an SE Linux auto relabel passing
by pretty quickly.
And then your system starts again.
You see the group boot prompt again.
That is expected behavior.
And then it will boot.
And once it's booted, you should have access to the root user password again.
So if I'm using the not listed here and I'm entering a root, this time I should be able
to log in as root.
As you can see, that worked.
It's also giving me a warning logging in as a privileged user.
You should avoid that.
Yeah, I know all of that.
And they're totally right about that.
But for now, I'll ignore.
Because this is RHCSA, we need the root shell for most of the things we're doing anyway.