This Blog primarily focus on providing solutions for administering Linux Operating system in Enterprise environment. I have put my best effort to ensure the solutions provided in this are accurate, easy to follow, effective, and helpful for Linux Users & System Administrators.
How to reset the permissions of installed RPM packages ?
One of our Developer has changed the permission of all the files under /etc to 777 by inadvertently executing the chmod command with 777 permission. Due to this, the system went into non-usable state.
The Linux 'rpm' command comes with an interesting switch known as '--setperms' using which we can restore the file-permissions of either one or more packages.
# rpm --setperms [package name]
To reset one specific RPM package:
# for pkg in $(rpm -qa | grep -w pkgname); do rpm --setperms $pkg; done Example: To reset the 'zip' package. # rpm -qa | grep zip <-- Check to see if the package exists # for pkg in $(rpm -qa | grep -w zip); do rpm --setperms $pkg; done
To reset the entire packages installed ( applicable in the situation I mentioned above):
# for allpkg in $(rpm -qa); do rpm --setperms $allpkg; done
Note: To restore the Group permission, we need to use the switch "--setugids".