Como Restablecer la Contraseña root

El Equipo de Documentación de Fedora Versión F41 Last review: 2025-02-11
Debe ser configurada una contraseña root mientras instala Fedora Linux, aunque ahora es sigerido para dejar la cuenta de root bloqueada y utilizar sudo. Este artículo describe como proceder si ha utilizado una contraseña root, pero por alguna razón no puede acceder a ella más.

Hay dos métodos comunes para restablecer la contraseña root si se olvida o se pierde.

  • En el Modo Rescate

  • Utilizar un Medio (USB/DVD/CD) de Fedora Live

Cómo restablecer la contraseña root en Modo Rescate

Al cambiar las contraseñas como root, no se solicitará la contraseña anterior.

Mientras arranca el sistema, se exhibirá el menú de GRUB2. Para arrancar el sistema en modo rescate utilice bash siguiendo estos pasos:

  1. Selecciona el apunte de arranque que desee para editar con las teclas de flechas.

  2. Select the entry you wish to edit by pressing e.

  3. Utilice las teclas de flecha para seleccionar la línea comenzando con linux, linux16, o linuxefi.

  4. Vaya al final de esa línea e incluya un espacio y lo siguiente rw init=/bin/bash.

    If your disk is encrypted, you may need to add plymouth.enable=0

  5. Press Ctrl+X or F10 to boot the entry

  6. Ejecute la instrucción:

    passwd

    Se le solicitará que introduzca la contraseña nueva dos veces.

    You can also reset a non-root user password using the same command if you specify passwd <username>.

  7. Rearrancar la máquina con:

    /sbin/reboot -f
  8. As the boot (GRUB) menu appears (same as the first step), again select the boot entry you want to use, press e, and add the autorelabel=1 option to the end of the command line. This will temporarily set SELinux in permissive mode (instead of the standard enforcing mode), which will allow the relabeling process to proceed, as well as trigger the relabeling process.

    Then, boot the modified entry with Ctrl+X or F10.

El sistema puede tomar un momento para iniciar mientras que el reetiquetado de SELinux cambia los permisos en el sistema de archivos. Si ve la pantala de inicio de Plymouth puede presionar la tecla ESC en su teclado para ver el progreso de SELinux.

Once it is complete, your system is ready and your password has been successfully changed.

For more information about SELinux states and modes, see Changing SELinux States and Modes.

Como restablecer la contraseña raíz con un Fedora Live Media

Para descargar y crear un USB vivo DE Fedora Workstation, sigue las instrucciones en la Documentación Rápida del Medio de Fedora USB Viva.

For additional information, specifically about live media using BTRFS, see also Restoring the bootloader using the Live disk

  1. Arranca el medio de la instalación Viva y elije Try Fedora.

  2. From the desktop, open a terminal and switch to root using su (the system will not ask for a password).

  3. To view your hard drive device nodes, enter df -H into the terminal. For this example we will use /dev/sda1 for the /boot partition and /dev/sda2 for the root / partition.

    If you are using LVM partitions, type: sudo lvscan and note the /dev path of your root partition. For this example we will use /dev/fedora/root.

  4. Create a directory for the mount point (use the -p option to create subdirectories):

    mkdir -p /mnt/sysimage/boot
  5. Mount the / (root) partition (be sure to use the actual device node or LVM path of your root / partition):

    To mount root on a standard partition scheme enter:

    mount /dev/sda2 /mnt/sysimage

    To mount root on an LVM partition scheme enter:

    mount /dev/fedora/root /mnt/sysimage
  6. Continue the process by mounting /boot, proc, /dev, and /run with:

    mount /dev/sda1 /mnt/sysimage/boot
    
    mount -t proc none /mnt/sysimage/proc
    
    mount -o bind /dev /mnt/sysimage/dev
    
    mount -o bind /run /mnt/sysimage/run
  7. chroot to the mounted root partition with:

    chroot /mnt/sysimage /bin/bash
  8. Change the root password:

    passwd
  9. Exit out of chroot with:

    exit

    and exit out of the terminal.

  10. Reboot your system and boot from the hard drive.

Congratulations, your root password has been successfully changed.

Additional Troubleshooting

  1. If you cannot enter rescue mode because you forgot the Firmware/BIOS password here are some options:

    1. Refer to your computer’s documentation for instructions on resetting the Firmware/BIOS password in CMOS memory.

    2. Temporarily move the system hard disk to another machine, and follow the procedures above to reset the root password.

  2. If you have set a password for your boot loader, refer to Creating and Using a Live Installation Image.

  3. If you want to reset the boot loader password, refer to the instructions on how to Reset the Bootloader Password.