Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 5798  / 2 Years ago, mon, december 20, 2021, 2:19:01

My friend did a chmod -R 777 /var by mistake. Now he has his /var folder permissions like this:



drwxr-xr-x 15 root   root     4096 Dec 29 17:36 .
drwxr-xr-x 23 root root 4096 Dec 10 11:15 ..
drwxrwxrwx 2 root root 4096 Dec 28 09:54 backups
drwxrwxrwx 22 root root 4096 Nov 9 11:06 cache
drwxrwsrwx 2 root whoopsie 4096 Dec 31 09:38 crash
drwxrwxrwx 2 root root 4096 Apr 23 2012 games
drwxrwxrwx 62 root root 4096 Dec 10 11:06 lib
drwxrwsrwx 2 root staff 4096 Apr 19 2012 local
lrwxrwxrwx 1 root root 9 Dec 29 17:36 lock -> /run/lock
drwxrwxrwx 19 root root 4096 Dec 31 09:54 log
drwxrwsrwx 2 root mail 4096 Apr 23 2012 mail
drwxrwxrwx 2 root root 4096 Apr 23 2012 opt
lrwxrwxrwx 1 root root 4 Dec 29 17:36 run -> /run
drwxrwxrwx 10 root root 4096 Jun 29 2012 spool
drwxrwxrwx 2 root root 4096 Dec 31 10:03 tmp
drwxrwsrwx 15 noufal www-data 4096 Dec 28 10:59 www


And I have mine as:



drwxr-xr-x 15 root root     4096 Dec 29 18:16 .
drwxr-xr-x 24 root root 4096 Dec 18 10:03 ..
drwxr-xr-x 2 root root 4096 Dec 31 10:00 backups
drwxr-xr-x 24 root root 4096 Nov 7 15:03 cache
drwxrwsrwt 2 root whoopsie 4096 Dec 31 09:55 crash
drwxr-xr-x 2 root root 4096 Apr 23 2012 games
drwxr-xr-x 74 root root 4096 Dec 29 17:30 lib
drwxrwsr-x 2 root staff 4096 Apr 19 2012 local
lrwxrwxrwx 1 root root 9 Dec 29 18:16 lock -> /run/lock
drwxr-xr-x 23 root root 4096 Dec 31 10:00 log
drwxrwsr-x 2 root mail 4096 Dec 31 10:39 mail
drwxr-xr-x 2 root root 4096 Apr 23 2012 opt
lrwxrwxrwx 1 root root 4 Dec 29 18:16 run -> /run
drwxr-xr-x 10 root root 4096 Jun 22 2012 spool
drwxrwxrwt 6 root root 4096 Dec 31 10:49 tmp
drwxrws--- 31 saji www-data 4096 Nov 27 15:05 www


We have similar systems. How can I reset the /var files and folders permission to the initial state, by not doing it individually for a file/folder.


More From » permissions

 Answers
6

One way is to install another machine or VM with the same version of the OS and on that machine run this two commands:



find / -exec stat --format "chmod %a %n" {} ; > /tmp/restoreperms.sh
find / -exec stat --format 'chown %U:%G %n' {} ; >> /tmp/restoreperms.sh


command 'find' finds the root directory and checks for their permissions using 'chmod' and save it to a temporary permission file.



Or this one that combines both:



/usr/bin/find / -exec /usr/bin/stat --format="[ ! -L {} ] && /bin/chmod %a %n" {} ; -exec /usr/bin/stat --format="/bin/chown -h %U:%G %n" {} ; > /tmp/restoreperms.sh


then, copy the /tmp/restoreperms.sh file to the machine with broken permissions:



scp /tmp/restoreperms.sh user@ip_address:/tmp/


scp securely copies the permissions stored to a temporary directory /tmp/
and execute it from there.


[#33441] Wednesday, December 22, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
splenueak

Total Points: 448
Total Questions: 118
Total Answers: 110

Location: Vanuatu
Member since Mon, Oct 3, 2022
2 Years ago
;