-1

I had a big mistake

I run this command on a centos 6.8 server:

chmod 0644 -R /* instead of chmod 0644 -R ./*

now directory listing on root directory / and all files failed when I run this command:

chmod 0775 -R /*

I get this error:

bash: /bin/chmod: Permission denied

how can I fix it without reinstall my centos?

4

2 Answers 2

5

Reinstalling the OS is by far the easiest and quickest way to fix this. Take an image backup first so you can recover anything that hadn't made it to your regular backup before the disaster happened.

The alternative is to boot from CentOS installation media or some other Linux live media, mount your CentOS system partitions on /mnt, and and then manually fix the permissions on every file and directory. Note that setting 775 globally is not enough to make your system usable again. There are files and directories that must have different permissions settings in order to work. This is long and tedious work, and you'll wish you had heeded the advice to reinstall.

1
  • If you've installed everything from RPM packages, you can use the output of rpm -qlva which will list the mode and ownership of every file shipped in every package currently installed which you can use to reset the mode of most of the files without reinstalling.
    – bodgit
    Aug 7, 2016 at 19:54
1

If it's not possible to reinstall the running system for obsure reason.

There is a way to install the same OS version with the same packages on another machine, and extract the filesystem rights that could be nearly restored.

sudo find / ! -path '/dev/*' ! -path '/proc/*' ! -path '/sys/*' ! -path '/tmp/*' -printf 'chmod -f %#m ' -print > fix_chmod.sh
4
  • This does though require that you can somehow get chmod working again .
    – user9517
    Aug 8, 2016 at 20:14
  • To get chmod working again, /usr/lib64/ld-linux-x86-64.so.2 /usr/bin/chmod +x /usr/bin/chmod should work, per serverfault.com/questions/189627/i-just-did-a-chmod-x-chmod (or substitute /usr/lib/ld-linux.so.2 for non x86_64 systems). Aug 8, 2016 at 21:16
  • 1
    @StefanLasiewski: He's removed execute permission from /usr/lib64/ld-linux-x86-64.so.2 as well
    – Ben Voigt
    Aug 8, 2016 at 22:21
  • @BenVoigt Ah good point. Aug 8, 2016 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .