I recently typed the command
sudo chmod 777 -R /
after that some things like
sudo -i
are not working normally. So I am wondering if there is any way I could reset the folder permissions to their original state?
|
I recently typed the command
after that some things like
are not working normally. So I am wondering if there is any way I could reset the folder permissions to their original state? |
|||||||||||||
migrated from stackoverflow.com Apr 20 '10 at 12:14This question came from our site for professional and enthusiast programmers. |
|||||||||||||
|
|||||||||||||
|
It is possible to come back from this messy situation. I ran again the same kind on issue (some bug in a script I was writing) and solved it, but you need to ask some expert's help. Be very cautious! First, my situation was easier to solve because I had a dual boot system (Ubuntu and my old Fedora install), but running the OS from a CD/DVD, or an USB key should do the same thing.
First I mounted my file systems like this (don't forget to create the mount points):
Then I ran the following command (my issue was only in a few - critical - directories) to copy the permissions on from the running system to the messy one (in fact, in my case, I installed an Ubuntu system in Virtual Box under fedora and got the permissions there):
And then I ran the restoreperms.sh script. I was able again to boot on Ubuntu. The content of restoreperms.sh will be something like:
I didn't test it but it must work for owners and owner groups too. Something like:
Of course, you have to take care here, that the UID and GID are the same on both systems, but for the system related users and groups, this shouldn't be an issue. Edit: Also, setting owner will nullify SGID and SUID flags, which causes weird problems (For example, you won't be able to perform sudo unless the permission is 4755). You must, and should only set permissions AFTER setting owners. DO SAVE complete file permission information along with owner information. Rk:
The right (combined) command is more something like:
Note that additional care may be required to account for parentheses in filenames (under locales, for instance) and that chown may silently unset setuid and setgid bits set by chmod. In the latter case, which would break, say, /bin/su and /usr/bin/sudo, you may need to swap the order of exec clauses above. |
|||||||||
|
|
After recover sudo or selecting recover mode at the boot It's possible to recover a whole system using debsums that verifiy file integrity and permissions. from the man page:
or limited to a specific path eg:
or limited to a multiple set of path eg:
|
|||
|
|
|
Always watch what you run as sudo. This thread explains that you can manually set some permissions back, and a script there helps with this, but still it's a big job. Rather follow the tips in the tread to save your installed packages (markings) and reinstall the OS, and apply your saved packages markings to get your applications back. |
|||
|
|
|
As far as I know, only System V packages and RPMs offer a command to repair file permissions. On System V (Solaris) it is pkgchk, with RPMs it is rpm --setperms. Unfortunately, no such command seems to exist for Debian / Ubuntu packages - but I might be wrong here. But even with the help of these commands, it's not a trivial task to bring your system back to a sane state, and by repairing it, you can easily cause new harm to your system - if you're not careful. Other than Joseph said, you're not the first one, and you will not be the last one to enter such a command. But the idea alone, to change file permissions to 777 on a Unix system, is a strong indication that you're not very experienced with this kind of system. The best you can do in this situation is to backup what you will need again (home directories, configuration files, mail files?), and try a fresh install. And you should be very, very careful, when you restore your - damaged - backup files. Good luck! P.S.: I'm just wondering what kind of problem you wanted to solve? |
|||
|
|
|
Wow, you killed it. It's dead! Try logging in and using the machine as root (since you enabled it), then change the group membership of root to users. This may or may not work because I've never tried it before but its worth a shot. |
||||
|
|
|
You can't undo a |
||||
|
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?