0

This question already has an answer here:

A colleague of mine told me that after he executed the below command, he's not able to login to the system.

  • No user can login via ssh.

  • Only normal users can login over physical console of the system, but no administrative commands are allowed, not even

    # sudo su -
    

And the culprit command which did the damage was

# chmod -R 777 /

My question, of course is, how to deal with such a system? Is there a way to restore the default permissions on a Linux system and what's best way to handle such situations?

marked as duplicate by G-Man, Jeff Schaller, slm Apr 29 '16 at 12:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    "what's best way to handle such situations?" Captain's Mast and a yard-arm. Fixes that problem every single time. – Warren Young Apr 29 '16 at 4:16
  • 1
    short answer: unfixable. but here's a dirty hack that can partially do the job on debian systems unix.stackexchange.com/a/49978/7696 - if you use a different unix or distro you may be able to adapt some of the ideas. or it's probably easier/better to just backup your data & config files and re-install from scratch. – cas Apr 29 '16 at 5:09
  • 1
    BTW, ssh is disallowed because the chmod -R 777 messed up the perms of all .ssh directories (including root's) and the files in them. ssh is very fussy about perms. If you want to login via ssh in order to attempt fixing this, the first thing you need to do is fix the home dir perms (/home/user/ and /root/) and the ~/.ssh/ perms. Also the perms for / and /home. – cas Apr 29 '16 at 5:13
  • 2
    If you can restore the backups to a new filesystem, and mount both the correct and incorrect filesystems on the same computer, you can use find to walk through the file tree and run a bunch of chmod commands, using the --reference option of chmod to copy the permissions. I'll see if there's an example online. – Mark Plotnick Apr 29 '16 at 11:32
  • 1
    Found it on serverfault. The answers there should fix things up: Copy permissions to identical tree on linux / unix – Mark Plotnick Apr 30 '16 at 20:57
0

If you can't login or su to a root user, the two remaining options are

  1. Boot from rescue media, and repair the damage
  2. Boot from installer, reinstall the system, then restore data from backups

Not the answer you're looking for? Browse other questions tagged or ask your own question.