Situation:
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.
Resolution:
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.
Syntax:
# 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
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".
hi..
ReplyDeleteThx for your command.
if we give chmod -R 777 /etc then ur command will not change file permission for all the content in /etc/..
It only change the default permission for /etc/ only.
@Guruprasanna, this command set can be used only to bring the system back to its default permission level, if someone mistakenly executed the chmod or chown commands in such a way that it impacts the functionality of the server. These are kind of System recovery commands.
ReplyDelete