2

On Centos 6.5 I accidentally typed

chmod -R 777 /

Ooops. I CTRL + C'ed out of it very quickly, but not before it'd started working away for a couple of seconds.

Consequences? Well, already

su root

isn't working (although logging in via SSH as root is). I'm not sure what else might have been affected.

Any ideas how I can proceed from here? Just re-install from backup or is there something clever I can do?

Many thanks.


Edit - what I'm really hoping for is some bash magic.

  • find files set to 777 in last hour on the server
  • set them to the permission value they should be for a standard Centos 6.5 install
8
  • 5
    There isn't really a way to undo a chmod. If you have backups it would be simpler to restore from there. Commented Mar 11, 2014 at 16:54
  • possible duplicate of sudo chmod -R 777 /
    – EBGreen
    Commented Mar 11, 2014 at 17:06
  • Well, I say backup. I'd have to re-install the server, which is always a pain. I'm tending towards the just leaving it and hoping for the best approach at the moment...
    – rastaboym
    Commented Mar 11, 2014 at 17:07
  • 2
    @EBGreen, OSX is on Unix, not Linux. They have similarities, but are not the same thing.
    – MaQleod
    Commented Mar 11, 2014 at 19:09
  • 1
    This question is not duplicate of the question linked, as the other questions and its solutions are specifically for OSX , so do not close this post.
    – Shekhar
    Commented Mar 14, 2014 at 22:30

3 Answers 3

1

Not only did you change the permissions on files, you may have changed directories and devices nodes. (According to the chmod man page, chmod never changes symlink permissions so at least those are safe.)

On CentOS 6.x, it is possible to find the package which installed a particular file with

$ rpm -q -f /bin/ls
coreutils-8.4-19.el6.x86_64

and then look up the original file mode with

$ rpm -q -l -v coreutils | grep /bin/ls
-rwxr-xr-x    1 root    root       109208 Jun 22  2012 /bin/ls

and then script it all together with find and chmod commands but this wouldn't fix everything and may actually make things worse. I would avoid it unless absolutely necessary.

Like the others have said, there isn't anything you can do to completely fix your system without restoring backups or reinstalling.

0
0

If you need to keep the system, I'd suggest to:

  1. Find the affected files. (My variant of chmod enters a directory and changes all files, then enters the directories alphabetically recursively.) Test what your chmod does -> this enables you to examine the exact list of files which are affected - hopefully chmod didn't reach your data (/home or /srv).

  2. Set all affected files to r--r--r--, all files which look executable to r-xr-xr-x, all directories to r-xr-xr-x and all /dev/ nodes to what another running linux system of your choice looks like. (That's lots of work!) (Remark: GNU/Linux systems are pretty good on running in read-only mode, but maybe some files must be writable - if from now the server doesn't start any more: bad luck) (Make sure that the log files are writable.)

  3. Reinstall all packages (make sure that the configuration files will be kept)

  4. Still, the system is not the same and may have severe security, performance and functional problems.

Hint for chmod recursion:

user:/tmp/chmod$ chmod -v -R 777 .
Modus von „.“ als 0777 (rwxrwxrwx) erhalten
Modus von „./a“ als 0777 (rwxrwxrwx) erhalten
Modus von „./a/1“ als 0777 (rwxrwxrwx) erhalten
Modus von „./a/2“ als 0777 (rwxrwxrwx) erhalten
Modus von „./a/1a“ von 0755 (rwxr-xr-x) in 0777 (rwxrwxrwx) geändert
Modus von „./a/1a/g“ von 0644 (rw-r--r--) in 0777 (rwxrwxrwx) geändert
Modus von „./a/2b“ von 0755 (rwxr-xr-x) in 0777 (rwxrwxrwx) geändert
Modus von „./a/2b/h“ von 0644 (rw-r--r--) in 0777 (rwxrwxrwx) geändert
Modus von „./b“ als 0777 (rwxrwxrwx) erhalten
Modus von „./b/1“ als 0777 (rwxrwxrwx) erhalten
Modus von „./b/2“ als 0777 (rwxrwxrwx) erhalten
user:/tmp/chmod$ 
0

This might solve some of your issues:

find . -type f -perm 777 -exec chmod 644 {} \;
find . -type D -perm 777 -exec chmod 755 {} \;

for some files / directories

You must log in to answer this question.

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