CentOS permission system recovery/restoration

Source: Internet
Author: User

CentOS permission system recovery/restoration

Sometimes the chmod-R is 777/, and the system is paralyzed ~ What should we do ?? Let's take a look.

First, you must prepare the same system as the faulty machine. For example, you can install a linux

Create a waynerQiu. c program in the new system. The content is as follows:

1234567891011121314151617 #include <sys/stat.h> #include <ftw.h> int list( const char *name, const struct stat *status, int type) { if (type == FTW_NS) return 0; printf ( "%s 0%3o\n" , name, status->st_mode & 07777); return 0; } int main( int argc, char *argv[]) { if (argc == 1) ftw( "." , list, 1); else ftw(argv[1], list, 2); exit (0); }

Compile the file and export the permission information.

1234 # Compile gcc waynerQiu.c -o waynerQiu.com # Permission to execute and export related directories . /waynerQiu .com / >> waynerQiu.txt

Copy the exported file to the faulty machine and execute the following script.

123456789101112131415 #!/bin/sh if [ $ # != 1 ] then echo Usage : $0 \<filename\> exit fi PERMFILE=$1 cat $PERMFILE | while read LINE do FILE=` echo $LINE | awk '{print $1}' ` PERM=` echo $LINE | awk '{print $2}' ` chmod $PERM $FILE #echo "chmod $PERM $FILE" done echo "change perm finished! "

You can save the script as a shell file, such as mygod. sh.

Then execute

1 mygod.sh waynerQiu.txt

After the program runs, restart the system to see if it has been restored?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.