Introduction

A colleague of mine made a serious mistake (running chown -Rf mysql on /!). This caused a huge mess, and we had to find a solution to restore the correct permissions.

Fortunately, Red Hat anticipated these kinds of errors and included the --setperms and --setugids options in the rpm command to repair permissions on installed packages. Basically, this gives you a way to repair your machine.

So if you also made a mistake like this, know that there is a solution on Red Hat.

Usage

Here are the two magic commands:

1
2
for u in $(rpm -qa); do rpm --setugids $u; done
for p in $(rpm -qa); do rpm --setperms $p; done

You’ll need to do a bit of verification afterward because this only repairs the permissions of files and directories contained in installed packages. Your personal files will not have their permissions restored with this method.

Resources

Last updated 04 Feb 2012, 17:50 +0200. history