Trashed Linux file permissions

130 pts.
Tags:
CentOS
chmod
Linux administration
Linux file permissions
Hi there I have two Linux CentOS 4.7 boxes and I have trashed the file permissions on one of them “chmod –R 776 .” I happened to be running Root at the top of the file system. Does anyone know if its possible for me to backup just the files permissions from my good box and restore them over the file permissions on the damaged box. Thanks for you help Jay

Answer Wiki

Thanks. We'll let you know when a new response is added.

The rpm command has modes to set the permissions and ownership of every file in every package back to the way they were when newly installed.

Run:

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

Go have a cup of coffee. Problem fixed.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • petkoa
    Hi, I will try to suggest a way to prepare the "correction" script using "find" on the healthy system. Just run as root (but this time in the home directory ;o)): echo "#! /bin/bash" > my_script ; find / -not -type l -not -regex "/(sys|proc|dev|tmp|home)/.*" -printf "chmod %m .%pn" >> my_script ; echo "# end" >> my_script ; chmod 755 my_script It's important to exclude symbolic links because in fact their target is chmod-ed (which is probably not what we want). You may opt not to exclude /tmp or /home (if you have no real users) but better keep yourself away from /dev, /proc and /sys. And they are dynamically populated anyway. The dot before %p will be helpful if you can't start your trashed system - and better don't listen to me if I tell going to / and running anything from there . You'll get something like this, just several tens Klines long (in 17 secons one of my servers produced ~75000 lines in a 4 MB file, so the generation time is not a problem - however, execution will take longer...) #! /bin/bash ... chmod 755 ./bin/mknod chmod 755 ./bin/mt-st chmod 4755 ./bin/mount chmod 4711 ./bin/ping6 chmod 755 ./bin/rmdir chmod 755 ./bin/shred ... # end Well, the real problem will be execution on the trashed system. Most probably, you will not be able to start it - so, run some live CD distribution, mount the system root partition at some mount point, mount other partitions under the appropriate locations, cd to the mount point and run the transferred script. Good luck, Petko
    3,120 pointsBadges:
    report
  • petkoa
    Well, just posted and saw that code is "censored" by the system... I didn't use it's buttons and all backslashes disappeared:
    find / -not -type l -not -regex “/(sys|proc|dev|tmp|home)/.*” -printf “chmod %m .%pn” >> my_script ;
    In -regex expression you should have backslashes before all ( and | , in -printf expression - before final n. Sorry, Petko
    3,120 pointsBadges:
    report
  • petkoa
    See, these backslashes disappeared again, though I used "code" button. Let me try escape them properly (?) n \n \n
    3,120 pointsBadges:
    report
  • petkoa
    Well finally, the proper code will be: (hopefully) echo “#! /bin/bash” > my_script ; find / -not -type l -not -regex “/\(sys\|proc\|dev\|tmp\|home\)/.*” -printf “chmod %m .%p\n” >> my_script ; echo “# end” >> my_script ; chmod 755 my_script By, petko
    3,120 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following