Q: 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.

A: 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:


*

*Restore from backup

*Reinstall

*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.

A: If you have a similar system at hand, you could use find to figure out the correct owner and group for each file, e.g. using:
find / -printf "%u:%g %p\n" > permissions.txt

which will produce output like the following:
root:root /
root:root /usr
root:staff /usr/local
root:staff /usr/local/man
root:staff /usr/local/games
root:staff /usr/local/lib
root:staff /usr/local/lib/python2.7
root:staff /usr/local/lib/python2.7/dist-packages
root:staff /usr/local/lib/python2.7/site-packages
root:staff /usr/local/lib/python3.2
[...]

You could then iterate through this and chown each file to its original owner and group.
while read line
do
    chown $line
done < permissions.txt

I doubt this will fix everything perfectly since permissions and files differ between systems, but it is a start and should at least get the base system back to the defaults

A: I'm more familiar with Fedora, but my suggestion would be to boot from a live CD and copy your data off the machine and re-install.
You could potentially use the package manager (apt/dpkg) information to figure out what the ownership of all the files on the system are supposed to be.  I could figure out how to do that with rpm, but I'm not that intimately familiar with apt/dpkg.  Any enhanced security such as SELinux may also complicate matters.
rpm -qa --list -v gives the required information on an rpm-based system, which you'd have to parse and feed to chown.  If you can find the equivalent for apt/dpkg you can get there.
