Restore the Original Permissions of Files using RPM


If in any case the package configuration files permissions or get changed in Linux, we can use rpm to restore the permissions.

I have changed the permission manully.

[root@lcfs packages]# rpm -qc wget
/etc/wgetrc
[root@lcfs packages]# ls -ltr /etc/wgetrc
-rw-r--r--. 1 root root 4479 May 16  2019 /etc/wgetrc
[root@lcfs packages]# chmod 777 /etc/wgetrc
[root@lcfs packages]# chown himanshu:himanshu /etc/wgetrc
[root@lcfs packages]# ls -ltr /etc/wgetrc
-rwxrwxrwx. 1 himanshu himanshu 4479 May 16  2019 /etc/wgetrc

Now lets restore original permissions using setperms:

[root@lcfs packages]# rpm -setperms wget
[root@lcfs packages]# ls -ltr /etc/wgetrc
-rw-r--r--. 1 himanshu himanshu 4479 May 16  2019 /etc/wgetrc

Also we can restore the original ownership as well using setugids:

[root@lcfs packages]# rpm -setugids wget
[root@lcfs packages]# ls -ltr /etc/wgetrc
-rw-r--r--. 1 root root 4479 May 16  2019 /etc/wgetrc