Question
How can I repair the ownership and File permissions for RPM controlled files and directories?
Answer
The rpm command comes with two built-in flags for handling ownership and permissions of files owned by rpms.
First though, we need to determine which module controls the file(s) or directories you need to repair. This can be done easily with a command similar to the following:
[root@example ~]# rpm -qf /etc/apache2/
ea-apache24-2.4.46-1.3.4.cpanel.x86_64
[root@example ~]#
and this command will allow us to review all of the files controlled by that rpm:
rpm -ql ea-apache24
Now that we know what package we're looking for, the first flag allows us to set the permissions of files owned by that rpm:
--setperms
As an example, let's take the following permissions (0123) on the path /etc/apache2, which as we saw above is controlled by the ea-apache24 rpm:
[root@example ~]# ls -ld /etc/apache2/
d--x-w--wx 6 root root 103 Oct 27 12:17 /etc/apache2/
[root@example ~]#
This is, obviously incorrect, however, using the flag above against the appropriate rpm we can quickly, and easily, reset this to the correct values without any guesswork:
[root@example ~]# rpm --setperms ea-apache24
[root@example ~]# ls -ld /etc/apache2/
drwxr-xr-x 6 root root 103 Oct 27 12:17 /etc/apache2/
[root@example ~]#
The second allows you to reset the owner and group for the files to the expected user and group:
--setugids
Using the same directory as previously we can see that somehow the ownership was changed:
[root@example ~]# ls -ld /etc/apache2/
drwxr-xr-x 6 frank frank 103 Oct 27 12:17 /etc/apache2/
[root@example ~]#
While it is uncertain why frank would need exclusive ownership of the apache directory, we can easily reset this in a similar manner to how we reset the permissions on the path earlier:
[root@example ~]# rpm --setugids ea-apache24
[root@example ~]# ls -ld /etc/apache2/
drwxr-xr-x 6 root root 103 Oct 27 12:17 /etc/apache2/
[root@example ~]#
Comments
0 comments
Article is closed for comments.