Friday, 25 August 2017

ubuntu - chown -R root.root /


So I was working and there was a directory that I was periodically changing to my user in a root terminal so that I could open the files in text editors, but I accidentally pressed / instead of . and this was the command I put out:


chown -R emil.emil /

Then immediately panicked ^C and put in another command, as I thought I could always change back the files I needed to access:


chown -R root.root /

So now I can't do su from emil to even try to fix this, as I'm getting permission denied error. I'm on Ubuntu could someone tell me if there is a way I could fix this, without absolutely reinstalling the whole thing.


TIP


If you are trying to get root access, and are getting this permission denied error when using su try this command:


gksu gnome-terminal

It will prompt you for the root password and open a new root terminal for some reason this works and gives me root access, when su doesn't.



Answer



The filesystem descending from / has a variety of ownership permissions in order to achieve different things.


The fix you attempted makes root the owner of everything, and so for many operations (including accessing files under /home/emil) root is the only user that will work.


So your options are:



  1. Restore from backup

  2. Reinstall

  3. Boot into single user mode and manually apply the correct owner to each file


I'll assume 1. is off the table, and 2. is not a preferred option.


In the Grub menu when you boot Ubuntu, you should have a recovery option at boot time. If you don't see the grub menu (this comes up before anything else after the bios) then hold down the left Shift and it will appear. Choosing this will boot into single user mode, where you are logged in as root.


From there you can begin to change ownership. The first thing would be


 chown -R emil /home/emil

Which will make you the owner of your own files. For the remainder, you may want to do an installation on another machine to compare file ownership, or start each service that you use in /etc/init.d and watch for reasons for failing (note that a service may fail simply because it is unable to write its logs to /var/log and so cannot even provide error reporting).


This would be an extremely time consuming process, but does get around re-installation. Note that any personal configuration you have made to Ubuntu and application settings will be stored in the /home/emil heirachy so copying these files somewhere else, re-installing the OS and applications, and copying them back is a far quicker option.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...