-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?

Tim
  • 33,870
  • 7
  • 56
  • 84
IVIR3zaM
  • 117

2 Answers2

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.

dmourati
  • 26,498
Tilman Schmidt
  • 4,335
  • 15
  • 29
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