Bookmark this page

Guided Exercise: Reset the Root Password

In this exercise, you reset the root password on a system.

Outcomes

  • Reset the lost root user password.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command runs a start script that determines whether the servera machine is reachable on the network. It also resets the root password to a random string and sets a higher time-out for the GRUB2 menu.

[student@workstation ~]$ lab start boot-resetting

Instructions

  1. Reboot servera, and interrupt the countdown in the boot-loader menu.

    1. Locate the icon for the servera console, as appropriate for your classroom environment, and then open the console.

      Send Ctrl+Alt+Del to your system by using the relevant button or menu entry.

    2. When the boot-loader menu appears, press any key to interrupt the countdown, except Enter.

  2. Edit the rescue kernel boot-loader entry, in memory, to abort the boot process just after the kernel mounts all the file systems, but before it hands over control to systemd.

    1. Use the cursor keys to highlight the rescue kernel entry (the one with the rescue word in its name).

    2. Press e to edit the current entry.

    3. Use the cursor keys to navigate to the line that starts with linux.

    4. Press End to move the cursor to the end of the line.

    5. Append rd.break to the end of the line.

      Note

      If it is difficult for you to see the text in the console, then consider changing the resolution when editing the kernel line in the boot loader entry.

      To change the console resolution, add either video=640x480 or vga=ask on the line that starts with the linux word, after rd.break. For most consoles, a resolution of 640x480 is enough. By using vga=ask, you can choose a more suitable resolution for your environment.

    6. Press Ctrl+x to boot by using the modified configuration.

  3. Press Enter to perform maintenance. At the sh-5.1# prompt, remount the /sysroot file-system as read/write, and then use the chroot command to enter a chroot jail at /sysroot.

    sh-5.1# mount -o remount,rw /sysroot
    ...output omitted...
    sh-5.1# chroot /sysroot
  4. Change the root password back to redhat.

    sh-5.1# passwd root
    Changing password for user root.
    New password: redhat
    BAD PASSWORD: The password is shorter than 8 characters
    Retype new password: redhat
    passwd: all authentication tokens updated successfully.
  5. Configure the system to automatically perform a full SELinux relabeling after booting. This step is necessary because the passwd command re-creates the /etc/shadow file without an SELinux context.

    sh-5.1# touch /.autorelabel
  6. Type exit twice to continue booting your system as usual. The system runs an SELinux relabel operation, and then reboots automatically. When the system is up, verify your work by logging in as root at the console.

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish boot-resetting

This concludes the section.

Revision: rh134-9.0-fa57cbe