Bookmark this page

Guided Exercise: Identifying and Recovering RPM Managed Files

Diagnose and repair file permissions and corrupted files that belong to packages.

Outcomes

You should be able to diagnose and repair file permission issues and corrupted files with the rpm and yum commands.

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

[student@workstation ~]$ lab start rpm-changedfiles

This command modifies RPM-managed files on your system.

Instructions

Users on servera are reporting that they cannot use the sudo or ls commands. Identify and resolve the issues that are preventing the commands from working.

  1. Log in to servera as the student user and attempt to switch to the root user with the sudo command. An error is expected.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    bash: /usr/bin/sudo: Permission denied
  2. Instead, run the su command to switch to the root user. Enter redhat as the password.

    [student@servera ~]$ su - root
    Password: redhat
    [root@servera ~]#
  3. Verify that the sudo and ls commands are not working and view the displayed errors.

    1. Attempt to print a message with the sudo command.

      [root@servera ~]# sudo echo test message
      -bash: /usr/bin/sudo: cannot execute binary file: Exec format error
    2. Attempt to list the contents of the root user's home directory with the ls command.

      [root@servera ~]# ls -a
      -bash: /usr/bin/ls: Permission denied
  4. Begin by investigating the sudo command. Run the rpm command to identify which package provides the sudo command and verify the contents of the package.

    1. Determine which package provides the sudo command.

      [root@servera ~]# rpm -qf /usr/bin/sudo
      sudo-1.8.29-7.el8.x86_64
    2. Verify the contents of the sudo package.

      [root@servera ~]# rpm -V sudo
      S.5....T.  c /etc/sudoers
      ..5....T.    /usr/bin/sudo

      The /etc/sudoers file is expected to be in the output because entries were added to the file since it was first installed. However, the /usr/bin/sudo file has content and timestamps that differ from when originally installed. The modified executable is expected to be the source of the issue.

  5. Run the yum reinstall command to repair the sudo package. Verify the package to confirm that the executable file is restored and that the sudo command works again.

    1. Run the yum reinstall command to repair the sudo package.

      [root@servera ~]# yum reinstall sudo
      ...output omitted...
    2. Run the rpm command to verify the sudo package. The /etc/sudoers file is still expected in the output.

      [root@servera ~]# rpm -V sudo
      S.5....T.  c /etc/sudoers
    3. Verify that the sudo command now works.

      [root@servera ~]# sudo echo test message
      test message
  6. Next, resolve the issue with the ls command. Run the rpm command to identify which package provides the ls command and verify the contents of the package..

    1. Determine which package provides the ls command.

      [root@servera ~]# rpm -qf /usr/bin/ls
      coreutils-8.30-8.el8.x86_64
    2. Verify the contents of the coreutils package.

      [root@servera ~]# rpm -V coreutils
      .M.......    /usr/bin/ls

      The M in the output indicates that the permissions, or mode, of the /usr/bin/ls executable file changed.

  7. Run the rpm command to restore the permissions of the files in the coreutils package, verify the package, and confirm that the ls command works again.

    1. Run the rpm command to restore the permissions of the files in the coreutils package.

      [root@servera ~]# rpm --setperms coreutils
    2. Verify the coreutils package. No output is expected if the verification succeeds.

      [root@servera ~]# rpm -V coreutils
    3. Verify that the ls command now works.

      [root@servera ~]# ls -a
      .  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .ssh  .tcshrc
  8. Exit from the root user shell and confirm that the sudo and ls commands now also work for the student user.

    [root@servera ~]# exit
    [student@servera ~]$ sudo ls -a
    [sudo] password for student: student
    .  ..  .bash_history  .bash_logout  .bash_profile  .bashrc
  9. Return to workstation as the student user.

    [student@servera ~]$ exit
    [student@workstation ~]$

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 rpm-changedfiles

Revision: rh342-8.4-6dd89bd