I was trying to run
chmod -R 777 ./ but ended up typing
chmod -R 777 / and set
777 on my entire machine. What can go wrong? How can I fix it?
Problems? Yes, lots. Can it be fixed? Sure. Faster than reinstalling? Probably not.
My recommendation is to reinstall. Keep a backup of the existing system, and restore the package list and the contents of files in
If this is a system with multiple local users, note that making some files world-readable has revealed some things that should have remained confidential.
If you really want to try repairing (more of a learning exercise than a practical recovery route), first restore the permissions of a few files. Note that while most files are now too open, a few are missing necessary setuid bits. Here are steps you should take before anything else. Note that this is not an exhaustive list, just an attempt at making the system barely functional.
Then you'll need to restore all the permissions everywhere. For files under
For files under
You may not notice it at first, but lots of things can and will go wrong. The main problem is that the entire security model for the entire system is broken. It's like having a body without a skin, organs all out in the air. It's bound to get infected because it's not meant to function like that. Even if it seems to work for a few minutes, you need to clean this up.
The best way would actually be to start from scratch. This way will greatly reduce your risk and give you a cleaner result in less time. If you have proper backups, this shouldn't be too trying an experience.
If you do try to clean it up, The primary way would be to tell your distro's packages manager to reinstall EVERYTHING on the system including, overwriting config files. Then use whatever verify system it has to look through them and make sure none of them are flagged as having files with permissions out of the ordinary. Next, work through things like user home directories and reset everything to sane permissions en masse, then work through the few things that should have special permissions (like ssh keys files). Lastly, do a full system find for everything marked as 777 and go through the list (it should be small if you've done the other steps thoroughly) and work through them one by one making sure they should be the way they are.
Some security-conscious programs will not start if certain files have too "loose" of permissions. As @ceving said,
The main thing that can go wrong is now any user can open, read, and write any file on your system. The two reasons why this are bad is: A) if a malicious user gains control of your system either through a an exploit or misconfiguration, he/she can modify anything on your system now, and B) you can delete anything you want even if you are not root, so you've just negated most of the protections of not running as root.
If you didn't back up the permissions beforehand you're in a bit of situation. You might be able to create a script that "fetches" a list of permissions from a freshly installed system and then "apply" those to everything on your system. I don't have such a script handy, though.
SOLUTION: I TESTED THIS IN CENTOS
This guy saved my job! (You need to access somehow)
1) To reset uids and gids on files and directories :
2) To permissions on files and directories
then change manually permisions to these files: