Basically i entered a wrong command on one of my most important cpanel server chmod -R 777 / And all the folders and files are changed to 777 permission and all the services like phpmyadmin and mail services has been stop no idea due to high permission. Can anyone suggest that how i can restore the permission of each files and folder to the default one.
-
This may be doable, but probably not on files that are not under package management. It would depend on what Linux you are using. – Kusalananda Mar 07 '19 at 14:52
-
If the distro is rpm based, you could use rpm --setperms
– Raman Sailopal Mar 07 '19 at 14:53
1 Answers
There is no magic procedure, the only way to restore it would be manually.
Fortunatelly the procedure is easy, but it should have to be performed carefully
Step 1: Copy the following script, paste it on your console to generate fixpermission script
echo ' chmod -R 755 /bin /boot /dev /etc/ /home /lib /lib64 \ /media /mnt /opt /run /sbin /srv /usr /var
chmod -R 777 /initrd.img /vmlinuz chmod -R 1777 /tmp chmod -R 555 /sys chmod -R 555 /proc chmod -R 700 /root
' > fixpermission
chmod +x fixpermission
./fixpermission
The above will create a script named fixpermission and run it by ./fixpermission if not already invoked.
Step 2: Run stat -c '%A %a %n' /* to show your proper directory and their permission as restored.
Example: Your directory permission structure should look similar to the following:
drwxr-xr-x 755 /bin
drwxr-xr-x 755 /boot
drwxr-xr-x 755 /dev
drwxr-xr-x 755 /etc
drwxr-xr-x 755 /home
lrwxrwxrwx 777 /initrd.img
lrwxrwxrwx 777 /initrd.img.old
drwxr-xr-x 755 /lib
drwxr-xr-x 755 /lib64
drwx------ 700 /lost+found
drwxr-xr-x 755 /media
drwxr-xr-x 755 /mnt
drwxr-xr-x 755 /opt
dr-xr-xr-x 555 /proc
drwx------ 700 /root
drwxr-xr-x 755 /run
drwxr-xr-x 755 /sbin
drwxr-xr-x 755 /srv
dr-xr-xr-x 555 /sys
drwxrwxrwt 1777 /tmp
drwxr-xr-x 755 /usr
drwxr-xr-x 755 /var
lrwxrwxrwx 777 /vmlinuz
lrwxrwxrwx 777 /vmlinuz.old
Information source:

- 547
- 3
- 9
-
Edited for a deeper explanation referencing the original source in the final. – Dasel Mar 07 '19 at 15:11
-
This solution make files that should not be user-readable like
/etc/shadow
or/etc/sudoers
readable and does not restore suid/sgid permissions on programs that need them (say/usr/bin/passwd
). This procedure does not give you a working system. – doneal24 Mar 07 '19 at 17:04