How to Recover Default File & Directory Permissions
Today, I come across a situation where, an application guy hit chmod command in wrong way. He hit below command where working directory was /usr
# chmod -R 777 * # pwd /usr #
In short he hit below commnad:
# chmod -R 777 /usr/*
Due to this command, the permissions of all files and folders under directory /usr got changed to 777. This situation can happen with any administrator. One can use the below command to recover default permissions of files and directories, provided those files and directories are part of any installed rpm packages.
# rpm --setperms -a
If you want to recover default permissions of file/directory of particular packages then you can use the below command.
# rpm --setperms PACKAGE_NAME
Here, PACKAGE_NAME is the name of the package. E.g httpd. Now, what if the ownership of any file or directory got changed. If you know the package name of that file then the below command can be used to set default user/group ownership.
# rpm --setugids PACKAGE_NAME
For all packages use -a option as below
# rpm --setugids -a
How to find package name of any file/directory
# rpm -qf [file name]
# rpm -qf /etc/ssh/sshd_config openssh-server-6.6.1p1-22.el7.x86_64