How to change the root password in Fedora

Image of the LXDE spin of Fedora.

In Gnu / Linux we can change the password of any user, anyone except root or superuser. Password that can only be changed if you are the superuser. But what if you forget the root password? What options are there to solve this? Should we reinstall the Gnu / Linux distribution?

Is there a solution for the problem of forgetting the root password, but it is true that each distribution has a different solution. Next we are going to explain how to make this root password change in Fedora. First of all, do not do this in production teams for fun because if there is an error you will lose all the information.

To change the root password we have to interrupt the start of Fedora Grub. We will interrupt it by pressing the E button when the Grub screen appears. A screen like the following will appear:

Grub screen in Fedora 26

So we go to the Linux16 line and we change the word set «rghb quiet» by

rd.break enforcing= 0

Now we press Ctrl + X to continue the loading process. If the system is encrypted, it will now ask us for the LUKS password.

With this we have made the Fedora system load in emergency mode, now we have to mount the hard disk with the following command:

mount -o remount, rw / sysroot

And we execute the chroot command to access the system. By typing the following:

chroot / sysroot

And now we can run passwd command to change root password. After executing the command, we will be asked to enter the new root password twice. Now we write Exit twice to reboot the system. After that we start the session as root and restore the grub changes by typing this:

restorecon -v /etc/shadow

And later

setenforce 1

With this we will have the new root password changed and we will be able to function without having to reinstall or lose our data.

More information - Fedora Magazine


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.