Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I accidentally run the following command as root chown mike -Rf / backups the point is that I added a space between / and backups my mistake, I stopped the command after 1-2 seconds, how can I recover from this? I have problems with DirectAdmin right now for example when accessing it I recive the error:

Unable to determine Usertype
user.conf needs to be repaired
http://help.directadmin.com/item.php?id=456

Or I stopped recieving emails, I dont even know what else is messed up right now...

share|improve this question
2  
Since it sounds like you have backups, I suggest comparing ownership info with the backups. –  derobert May 1 '13 at 15:53
    
Note that the chown may also have cleared any setuid or setgid bits on the affected files, even if they were originally owned by root. –  Keith Thompson May 1 '13 at 22:25
add comment

3 Answers

up vote 3 down vote accepted

There is no way to change this back without reverting to your backup as the system does not keep track of revision of ownership.

Best is to make a backup now, so any further changes can be rolled back.

Reinstalling the packages on your system probably resolves most of the ownership problems. On Debian/Ubuntu I would do:

apt-get install --reinstall package

on an rpm based system something like rpm -Uvh --force package.rpm for anything that is giving trouble. If properly setup a package will not overwrite configuration files that you changed.

If you have another similar system, or a backup you can retrieve original ownership information from that an apply to your system. First make list of files and directories you are interested in using:

find / -user mike

and use that list to find not-mike-owned files in the backup or similar system.

share|improve this answer
    
I suggest you to check this answer about package reinstallation under a Debian based system. –  Totor May 1 '13 at 23:09
add comment

I'm afraid that the only solution you have is to compare with another installation of the same distribution and reset the owners correctly.

share|improve this answer
add comment

That depends on the OS you are running.

If it is Solaris 10 and older, you can fix all the owner issues affecting files and directories belonging to a package with the following command:

pkgchk -f

With Solaris 11, that would be:

pkg fix

I believe AIX has a similar package fix command.

If you run a rpm based OS (Red Hat, Fedora and the likes), you should be able to run

rpm -aV

to detect the files and directories with discrepancies against the package database. You might then fix them by running:

rpm --setugids <package-name>

But you would need to pass each affected package name. Alternatively, you might simply run:

for package in $(rpm -qa); do rpm --setugids $package; done

If you are running a debian based OS, I'm afraid file ownership isn't stored in the package database so you would need to either use your backup if any as a reference to restore the ownership, or find a similar system for the same.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.