How to restore file permissions of the installed package to its default on Linux?

Hello all,

(Please, note that in command string instead of “” there are two dashes “- -“ like “–setperms” it is “– -setperms”)

By mistake, I run the following command on / directory:

chmod -R 777 *

I stopped this command, but unfortunately some file permissions were changed.

Because of that, I was not able to connect to the server with WinSCP and ssh was not working.

I looked in to the /var/log/messages and found the following entry:

Sep  6 15:02:37 stbynode sshd[24226]: fatal: /var/empty/sshd must be owned by root and not group or world-writable.

I run the following command on another server:

ls -la /var/empty/sshd
total 16
drwx–x–x 3 root root 4096 Sep 3 21:07 .
drwxr-xr-x 3 root root 4096 Sep 3 21:07 ..
drwxr-xr-x 2 root root 4096 Sep 3 21:36 etc

On my server it was:

ls -la /var/empty/sshd
total 16
drwxrwxrwx 3 root root 4096 Sep 3 14:00 .
drwxrwxrwx 3 root root 4096 Sep 3 14:00 ..
drwxrwxrwx 2 root root 4096 Sep 3 14:00 etc

You can change these permissions by hand (that will be boring if not only one file permissions have been changed)but there exist one very useful command:

rpm  –setperms {packagename}

This will reset package permissions, because of rpm database contains permission information.

So I run the following :

for p in $(rpm -qa); do rpm –setperms $p; done

Note this script will reset permissions of the  installed package, not user created file…

After completed this command , I was able to connect to the server with WinScp and  /var/empty/sshd permissions were set to drwxr-xr-x

To avoid such kind of situation my advice would be to save permission information everyday. By running the following command using crontab:

find / -exec stat –format “chmod %a ${MPOINT}%n” {} \; > /tmp/permissionsbackup.sh

Good Luck , I hope the post was helpful…

Advertisements

One Response to How to restore file permissions of the installed package to its default on Linux?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: