# Accidentally run chown -R user /*



## JazzSinatra (Jul 15, 2019)

I accidentally did run `chown -R my_username /*` instead of `chown -R my_username ./*`, so how do I undo this? Can I simply run `chown -R root /*` and then `chown -R my_username /home/my_username`?

EDIT: The installation is pretty fresh. I installed this system couple of days ago and it doesn't have any other users yet than "my_username".


----------



## jdakhayman (Jul 15, 2019)

If you dont have anything setup and are still sitting on a basic install, just reinstall FreeBSD.


----------



## JazzSinatra (Jul 15, 2019)

jdakhayman said:


> If you dont have anything setup and are still sitting on a basic install, just reinstall FreeBSD.


Well, it seems that I made a mess. Fortunately, I only do server stuff non-professionally as a hobby.


----------



## SirDice (Jul 15, 2019)

JazzSinatra said:


> I accidentally did run  chown -R my_username /* instead of  chown -R my_username ./*,


Ouch. It could be worse though, I once did `rm -rf *` _thinking_ I was in /usr/ports. I wasn't. It was /usr 



JazzSinatra said:


> so how do I undo this


It depends on how far it extends but this should fix most of it:

```
mtree -e -p / -U -f /etc/mtree/BSD.root.dist
mtree -e -p /var -U -f /etc/mtree/BSD.var.dist
mtree -e -p /usr -U -f /etc/mtree/BSD.usr.dist
```

There are a few more files in /etc/mtree that might be needed, mtree(8) is a little cryptic but extremely useful.


----------



## JazzSinatra (Jul 15, 2019)

SirDice said:


> Ouch. It could be worse though, I once did `rm -rf *` _thinking_ I was in /usr/ports. I wasn't. It was /usr
> 
> 
> *It depends on how far it extends* but this should fix most of it:
> ...


The command did go through the whole system.


----------



## JazzSinatra (Jul 15, 2019)

Should I run `portmaster -af`?


----------



## SirDice (Jul 15, 2019)

For /usr/local/ most of it should be `chown -R root /usr/local`. You may have some services installed that have files/directories in /usr/local/etc/ that should be owned by a specific user account instead though. But those are easy enough to identify.


----------



## ralphbsz (Jul 15, 2019)

Suggestion that's more thorough than educated guesses, and perhaps a little less work than a full reinstall: Find a sacrificial machine, and install a virgin FreeBSD setup on it. Then use the find command to find things that are not used by root: `find / \! -user root`. Now, this will give you many hundreds or many thousands of hits. To make that list more manageable, try to find directories, and stop at the top level directory: `find / \! -user root -type d -prune`. On my home system, this finds 62 directories not owned by root (excluding /home). Fixing those should get you pretty close.

An ideal solution would be to use the virgin system, and make a complete list of all files (with user and group), and then use that list to check all the files on your production system. That would probably be half hour of script writing.


----------



## scottro (Jul 16, 2019)

SirDice I once did the same thing. Fortunately, it was a completely fresh install. This was back with FreeBSD-4.x when one routinely ran chflgs then removed /usr/obj. I though I was in /usr/obj.  Then ran cd /usr/src and got no such directory or similar.

I think everyone's done similar, like a dd with of=  being the wrong place, etc.


----------



## Sevendogsbsd (Jul 16, 2019)

Did that very thing that OP did on Gentoo once, after a stage 1 install and 2 days of compiling. I was very sad.


----------



## scottro (Jul 16, 2019)

I remember when Gentoo was very new, and I did the editing of something. Probably make.conf   I wasn't used to nano and put :x at the end of the file, vi habit. I was the first to publicly admit it on the Gentoo mailing list at the time, and after my confession, (like you 2 days compiling or possibly 3--I think I used KDE at that time), lots of other people admitted they'd done the same thing.  For those who don't remember, when Gentoo first came out, its stage one install, which involved compiling the whole system, only included nano, not vi.


----------



## SirDice (Jul 16, 2019)

scottro said:


> I think everyone's done similar, like a dd with of= being the wrong place, etc.


Having done stupid things is a rite of passage. If you've never made a mistake like this you haven't done anything worthwhile yet


----------



## CraigHB (Jul 16, 2019)

Yep, I've done similar.  It ~is~ a rite of passage, isn't it.  FreeBSD (and all Unix variants for that matter) expect you meant to enter whatever you typed, no "are you sure" business.  You get used to that.


----------



## ralphbsz (Jul 16, 2019)

General statement: There are two kinds of people. Those who have really good backups, and those who have not lost data yet.

And the largest source of data loss is user error, with accidental deletion as #1. It is soon followed by mistakes made by service personnel. In storage systems, the classic error (happens all the time): In a redundant disk array, one disk fails. This is not an emergency, because we have redundancy, and the array continued functioning. A field service person is sent, or the admin goes to fix it. Too often, they leave the dead disk in the system, and pull a functioning disk out instead, throw it in the trash, and put a blank disk in. And unless you have high degrees of redundancy, you now have data loss.

This then leads to my advice for how to administer a computer system: You hire a person and a dog. The person is there to feed the dog. The dog is there to bite the person, if they try to touch the computer.


----------

