Thursday 11 December 2014

Tips For Restoring Permissions and ownership of Files in Redhat 6/7

Problem:
=======
Permissions and Ownership on critical system files (in /etc/) directory modified. This may cause the system to not boot, lots of errors and Kernel Panic.
cause:
=====
Someone accidentally typed chmod -R 777 /etc
Solution:
=========
The RPM package manager maintains a database for all files that it installs onto the system. This includes information such as the filename, installation path, owning package and the file system ownership and permissions (including SELinux file context information). In the event that ownership or permissions are inadvertently changed, for example, through accidental misuse of the chown or chmod commands, it is possible to revert these to their values as stored in the database.
1. To re-set ownership and permissions for all packages on the system:
root@ubuntu12:~# rpm –setperms -a
root@ubuntu12:~# rpm –setugids -a
2. To re-set ownership and permissions for a specific package on the system
root@ubuntu12:~# rpm –setperms <package name>
root@ubuntu12:~# rpm –setugids <package name>
……………….OR …………..
1) To reset uids and gids on files and directories :
root@ubuntu~:# for u in $(rpm -qa); do rpm –setugids $u; done
2) To permissions on files and directories
root@ubuntu12:~# for p in $(rpm -qa); do rpm –setperms $p; done

Article Source - http://www.rhce.co.in/tips-for-restoring-permissions-and-ownership-of-files-in-redhat-67/