Issue
My fingers decided to betray me and press the enter key a moment too soon, and I have managed to run chmod -R 777 /
across a whole drive. I have no physical access to the device.
I do however, still have a connected session where I am root and a clone-ish (minus web content) server which I guess I could probably dump permissions from i.e
./var/www/htdocs/ckeditor/plugins/link/images/hidpi:
total 12
drwxrwxrwx 2 user user 4096 Aug 27 20:43 .
drwxrwxrwx 3 user user 4096 Aug 27 20:43 ..
-rwxrwxrwx 1 user user 1597 Sep 6 20:51 anchor.png
./var/www/htdocs/ckeditor/plugins/liststyle:
total 12
drwxrwxrwx 3 user user 4096 Aug 27 20:40 .
drwxrwxrwx 32 user user 4096 Aug 27 20:41 ..
drwxrwxrwx 2 user user 4096 Aug 27 20:40 dialogs
./var/www/htdocs/ckeditor/plugins/liststyle/dialogs:
total 12
drwxrwxrwx 2 user user 4096 Aug 27 20:40 .
drwxrwxrwx 3 user user 4096 Aug 27 20:40 ..
-rwxrwxrwx 1 user user 2939 Sep 6 20:48 liststyle.js
Is there any way to utilize these two facts to undo the damage? Is it possible to build a script to harvest that data and use it to set permissions?
Solution
On the good server, dump the file permissions for non-symlinks on the disk filesystem:
$ find / -xdev \! -type l -printf 'chmod %#m %p\n'
...
chmod 0755 /bin/cp
...
chmod 0600 /etc/iscsi/iscsid.conf
...
chmod 0744 /lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/video/backlight/progear_bl.ko
...
chmod 0644 /usr/lib64/perl5/auto/POSIX/stat.al
...
Copy and paste the output into your open root session on the messed-up server.
Then go install ZFS for Linux and start taking regular snapshots :P
Answered By - andrewdotn Answer Checked By - Candace Johnson (WPSolving Volunteer)