chwnd!

I did something incredibly stupid.
I wanted to do this:

sudo chown <me> somedir/*

Instead, I did this:

sudo chown <me> /*

Oops! I realised what was happening, and Ctrl+C’d. When I tried to put things back to normal, I realised i couldn’t sudo. sudo gave me some error about /etc/sudoers having the wrong uid. It turns out this was because /etc/sudoers was one of the things that got chowned before I stopped chowning things.

So if you’re ever in such a situation, here’s what you do:
In ubuntu, simply boot into recovery mode, with other distros, you may have to manually log in as root. Then chown your sudoers, and anything else that you messed up and reboot.

What I did was simply this:

chown -R root:root /bin
chown -R root:root /boot
chown -R root:root /etc

Those being the only three dirs affected. However, there may have been files that should belong to me and shouldn’t be chowned to root (there weren’t in this case, but if I hadn’t Ctrl+C’d fast enough, there would have been such files). So really, I should be checking for files with me as owner, but root as the group, and then only chowning those. In which case the following might be a better way (might because its untested)

ls -Rl / | grep "<yourusername>[[:space:]]root"  | awk '{print $8}' | xargs chown -R root:root

Of course this wont work if you have spaces in your filenames. Just change the awk part appropriately (it’ll end up uglier!)

Advertisements

~ by hellfeuer on February 19, 2008.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: