Why does chmod 777 -R / leave the system unusable?
Solution 1:
There are a couple of reasons.
First in addition to the usual read/write/execute permissions there are some other bits that file permissions contain. Most notably setuid
and setgid
. When a program with one of these permission bits is set is run it gets the "effective UID" and/or "effective GID" of the program's owner rather than the user that ran it. This allows programs to run with more permissions than the user that ran them. It is used by many crucial system utilities including su
and sudo
. Your chmod
command clears these bits leaving the utilities unusable.
Secondly some programs (notably ssh
) do a sanity check on file permissions and refuse to use files with permissions they see as insecure. This reduces the risk of careless admins accidentally leaving security holes but it makes dealing with wiped-out file permissions all the more painful.
Solution 2:
A short answer.
Linux system requires specific permissions for certain programs like sudo
, etc.
When you run chmod 777 -R /
you wipe all permissions and replace them with 777
. This makes the system unusable unless you manually restore all the permissions.
In practice it is much faster and easier to re-install.
The problem is that many system programs are designed a way that they do not start if they "do not like" the permissions. This is made for security reasons.
I think it is more important to explain how to handle the system design in paractice than to explain why each program fails to work with wrong permissons.
If you really want all users to have unlimited permissions in Ubuntu, you can add all users to the sudo
group instead of changing file and directory permissions. That will have the same effect, but will not ruin the system.
Another way (a very bad one) is to activate root account and allow everyone to login as root.