5

I was setting up a Ubuntu Server and I wanted to allow the FTP client to access the /etc/ folder. So I used the chown command to allow my account to use it. However, this changed the ownership of sudo and broke it. I can't run any commands as sudo because the owner is not root and I cannot change the owner because I have to use sudo.

I tried booting into recovery mode as root and running chown -R root /etc and chown -R 0 /etc but neither worked.

Is there anyway to fix this without re-installing Ubuntu?

1
  • Permissions of this type are discretionary access controls. They're called discretionary because the operating system can use its discretion to decide whether it should respect them or not. It is possible to override DACs by mounting your drive in another system (or even booting a Linux Live CD), acquiring root through that system, and setting the permissions appropriately. Nov 6, 2012 at 21:33

3 Answers 3

3

Reboot, hold down right shift key to bring up the grub2 boot menu. Then follow these instructions to enter single user mode.

How do I boot into single user mode from grub?

In single user mode you can fix the file permissions because you are automatically the root user.

Generally speaking, if it's just the file ownership that changed. You can run:

chown -R root:root /etc

That will change ownership and group back to the default root.

I have an ubuntu server 12.04 LTS here and there are a small number of files/directories beneath /etc that have a different group ownership. Aside from this, all files are owned by root. The files with the different group ownership are:

/etc:
-rw-r----- 1 root daemon   144 Oct 26  2011 at.deny
drwxr-s--- 2 root dip     4096 Aug 22 12:01 chatscripts
-rw-r----- 1 root shadow   697 Oct 31 12:58 gshadow
-rw-r----- 1 root shadow  1569 Oct 31 13:00 shadow

/etc/chatscripts:
-rw-r----- 1 root dip  656 Aug 22 12:01 provider

So you can run the chgrp command on those files after initially running chown first. Then you should have everything restored back to how it should be. It shouldn't take an average user more than 10mins.

e.g. 
  chgrp shadow /etc/shadow

Oh and one final step. After you've done the changes reboot.

/> reboot
0
1

You can boot your computer using an ubuntu-cd and mount the file system in question and fix the permission & ownership on these file manually.

But /etc contains A LOT of files that needs fixing.. could take some time.

4
  • Really any live CD would work, you are logged in as Root by default on them.
    – nerdwaller
    Nov 6, 2012 at 21:33
  • How does one fix the ownership manually? Nov 6, 2012 at 21:37
  • Also, could I not just fix the sudo folder than do the rest through chown? Nov 6, 2012 at 21:38
  • "chown root:root /etc" Might as well do it all at once. Next time, add yourself to an elevated group that has perms for the folders you want without passwords. You can use "visudo" and "groupadd".
    – nerdwaller
    Nov 6, 2012 at 21:43
1

If you need to fix it that first check what the permissions should be. They might not all be root:root. Worst case they are not and you discover this a lot later after trying to figure out why something else does not work.

Install an identical version of Ubuntu somewhere. Check all permissions.

If they are all root:root then get a root prompt. Either by booting a liveCD or somehow boot into single user mode. (e.g. LILO with init=/bin/bash, or shift-GRUB). Mount the filesystem containing /etc and chown the files to the right permissions.

If not all files are root:root then you might want to construct a script to set the values (use the identical install you made earlier to look up what those values are).

If this is a nice fresh install you can try to copy a fresh etc from the other install (move the old /etc to another place, e.g. to mv it to etc.backup and copy a fresh one from a pendrive. If you do this you will need to make sure what password is set because you are also overwriting the password files)

However if this is a relative new install which you are still setting up: Just reinstall.

Quickest, safest, but least educative.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .