Bookmark this page

Guided Exercise: Resetting the root Password

Reset a root password.

Outcomes

You should be able to reset a root password without having another form of root access to a machine.

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

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

This command changes your system's root password and increases the grub2 boot menu timeout value.

Instructions

A colleague installed a new servera system, but does not remember the root password. The server is otherwise configured properly, but the documentation does not include the password.

You are asked to reset the root password to redhat.

Important

For this exercise, assume that you do not have ssh access to servera, and that the student account on servera does not have full sudo access. Use a direct virtual console connection to servera. Obtain access to the servera console with an appropriate method for your classroom environment.

  1. Open a console to your servera system, log in as the student user, and reboot the system. Press any key except Enter to pause the GRUB menu timer when it appears, and force the system to pause the boot sequence during execution of the initial ramdisk.

    1. From the console, log in to your servera system as the student user and run the reboot command.

      servera login: student
      Password: student
      [student@servera ~]$ reboot
    2. Press any key except Enter to pause the GRUB menu timer when it appears.

    3. Highlight the default entry, and press e to edit it.

    4. Scroll down to the line that starts with linux, press Ctrl+e to jump to the end of the line, remove all console= settings (if any), and append rd.break.

    5. Press Ctrl+x to boot with these modified settings.

  2. Change the root password to redhat, force SELinux to relabel all files during the next boot, and reboot the system.

    1. Remount the file system on /sysroot with read-write capabilities.

      switch_root:/# mount -o remount,rw /sysroot
    2. Change the root directory to /sysroot.

      switch_root:/# chroot /sysroot
    3. Set the root password to redhat.

      sh-4.2# echo "root:redhat" | chpasswd
    4. Force SELinux to relabel all files during the next boot.

      sh-4.2# touch /.autorelabel
    5. Reboot your system by typing exit twice.

      sh-4.2# exit
      exit
      switch_root:/# exit
      exit
  3. Log in to the console as the root user with the password redhat.

    servera login: root
    Password: redhat
    [root@servera ~]#

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

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

Revision: rh342-8.4-6dd89bd