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?