How to restore the default chown permissions on a directory / file? [duplicate]
I am using Ubuntu 13.04 x86_64.
I wanted to own whole stuff in my home directory. So I executed these two commands.
sudo chown -RcH rootkea ~
sudo chown -RcL rootkea ~
Now due to those symbolic links linked to some other files in filesystem I have accidentally owned files which reside outside of my home directory.
The immediate consequences which I noticed are:
-
sudo not working
$ sudo sudo: effective uid is not 0, is sudo installed setuid root?
- system has become so slow. It just gets hanged when I click on shutdown / reboot. Each time I have to manually power off the machine.
-
creates a log file
/var/log/cups/error_log
of indefinite size which consumes the last byte of my hard drive (after considerable time). Last time it was 17.8 GB!
The content of the file was only these two lines repeated uncountably:E [24/May/2013:02:27:52 +0530] File "/usr/lib/cups/notifier/dbus" has insecure permissions (0100755/uid=1000/gid=0). W [24/May/2013:02:27:52 +0530] Notifier for subscription 531 (dbus://) went away, retrying!
So clearly cups
program is screwed too.
Now I have no idea about how many other programs have gone to unusable state.
Is there any way to undo the effects of above mentioned two commands ?
How can I restore the default permission settings to whole filesystem ?
Solution 1:
As gertvdijk suggests (by reference to this question), reinstalling is almost always the best and easiest way to fix this (and the only way you can be sure will completely fix it), especially if you don't know exactly where the permission were changed or what they were changed from.
This method, which private has suggested, might work, and you may consider it worth a try. However, there is some variation from version to version of where files and folders are and what their ownership and permissions should be. Furthermore, with any solution besides reinstalling, you'll never know if there are some files or folders with wrong permissions, which may at some point in the future cause problems.
You can usually fix--or at least make progress--on the problem of sudo
not working (i.e., problem 1, as you've listed it) by fixing its ownership:
pkexec chown root:root /usr/bin/sudo
In a situation like yours, that's mainly useful as a convenience measure to make it easier to perform whatever administrative tasks you need to get done before reinstalling. (Or before attempting to apply some more complicated solution.) A backup is definitely in order now, if your backups of important files (e.g., documents) are not completely up-to-date.
Finally, please note that it's only ownership, and not permissions, that were modified. So you might try recursively changing directories' ownership back to root. However, that is not that likely to fix the problem either, because:
- it's unclear if you know exactly what directories have been changed.
- some files should not be owned by root because they have to be accessed by less privileged parts of the system; setting their ownership or permissions too restrictively could break the system.
- some files could cause security vulnerabilities if owned by root. A setuid executable always runs as the user who owns it. Your system may contain setuid executables that are intended always to run as some non-privileged user; making them run as root could be bad. Or someone may have--intentionally or unintentionally--created an setuid file (without having permissions to make it owned by root). If you make it owned by root, it will execute as root, no matter who runs it. That could be very bad.
So, if this is a production system, you should just reinstall.