How to reset the root password when you forget it

Groot says: I'm root

In Linux and other Unix environments we have user passwords and also that of the root account. When we forget the password of a user there is no major problem because with the root account or using sudo we can use certain administration tools to recover our lost user password or simply change it for a new one. On the other hand, when that happens to us with the root account, the all-powerful one, things are somewhat more complicated, but it is not the end of the world either ...

In est simple totorial we are going to teach you how to recover or reset the root password if you have forgotten and cannot access your privileged account on Linux. The method that I am going to describe is common for all distributions, although it could vary a bit depending on whether you use another bootloader, etc., but if you use a known distro with GRUB you will only have to follow the following steps:

  1. Restart your computer or boot it if it is not on, but keep an eye out for the GRUB screen, since you have to perform some operations on them. Therefore, if the countdown begins to enter the default entry, move the selector so that the count stops and gives you time. In case the GRUB screen does not appear because you do not have time, you will have to modify the GRUB configuration so that it appears, if you do not know how to leave a comment and I will try to explain it to you ...
  2. Now once we are in GRUB, press the E key to edit some options.
  3. Find a line where appears the name of the kernel binary image that is loaded and whose line ends with "init = / bin / bash". If you look at this line you will see that there is a read-only (ro) parameter that you must change to read-write, that is, rw.
  4. Now press F10 to save changes and restart the computer and what we will get now will be a bash shell prompt.
  5. Now you must work with the tools that we have in this shell to change root password:


mount -n -o remount,rw /


passwd root (aquí cambiamos la contraseña de root por la nueva,y si quieres puedes cambiar la de otro usuario usando el nombre de usuario en vez de root)


exec /sbin/init

With these three commands it is restarted once we have changed the password and we can enter the distro as we normally do ...

There are other alternatives to this method, such as using a LiveCD, or even copying the hash of a known password into the field corresponding to the root account of / etc / shadow, but I do not recommend the latter, since if you forget to change it once you have access, it would not be safe.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  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.

  1.   Carlos Saldaña said

    "With great power comes great responsibility" - Uncle Ben

  2.   arcane said

    Excellent contribution Isaac. Thank you.

  3.   davidcrx said

    Now for an article on how to password protect grub.

    Very good post.

  4.   Javi Happy said

    Thanks for the article, I agree with david, now it's time to protect the grub to avoid this, because then "anyone" could mess it up.

    A greeting.

  5.   Sebas said

    And then an article on how to reset your GRUB password when you forget it.

  6.   Worth said

    I cannot enter the VAMI page of VCenter. The administrator who managed it left and did not leave the password. I have tried with the 3 possible users (root, with another user that put the old administrator and with the local user that they mention administrator@vsphere.local of my Vcenter but I do not enter. I don't understand the SSH connection either. I have the MobaXterm program for the SSH connection but I don't understand how to connect to the address that I have of my VCenter. What can I do. Greetings.