System Recovery – Fixing a Broken System After ‘chmod -R 644 /’

permissionssystem-recovery

I use debian jessie and I have done one of those bad mistakes and broke my system with a mistyped command and worse mistakes that follow in such situations.

Trying to fix some permissions I mistakenly used chmod recursively on root folder:

# chmod -R 0644 /

and then realizing immediately I rushed in doing something to stop it but the system was frozen and the worse mistake was the hard powering off the system.

Now I think I have some user manager problem and after booting with some "failed to start service" messages I don't have the Gnome user login and I can't also login in console. And this is what that flashes several times and then stays on screen:

[ ok ] Created slice user-113.slice
       Starting user manager for UID 113...  
[ ok ] Started user manager for UID 113  
[ ok ] Stopped user manager for UID 113  
[ ok ] Removed slice user-113.slice 

Best Answer

The good news is that all your data is still there. The mixed news is that your system installation may or may not be recoverable — it depends where chmod stopped.

You will need to boot into a rescue system to repair it. From the rescue system, mount your broken installation somewhere, say /mnt. Issue the following commands:

chmod 755 /mnt
find /mnt -type d -perm 644 >/mnt/bad-permissions
find /mnt -type d -exec chmod 755 {} +

The first find command saves a record of directories with bad permissions into a file. The purpose is to see where permissions have been modified. The second find command changes all directories to be publicly accessible.

You now have a system where all directories listed in /mnt/bad-permissions and all files in these directories are world-readable. Furthermore files in these directories are not executable. Depending on which files were affected, this may be easily repairable or not. See Wrongly set chmod / 777. Problems? for what you can try to get the system functional, to which you should add

chmod a+x /bin/* /sbin/* /usr/bin/* /usr/sbin/* /lib*/ld-*

But even if you manage to get something working, there's a high risk that some permissions are still wrong, so I recommend reinstalling a new system, then restoring your data. How do I replicate installed package selections from one Debian system to another? (Debian Wheezy) should help.