I accidentally set owner of root folder (/) and all subfolders to one user by command
$ sudo chown -R 'userName' /*
Now I wanna set owner back to root user by command
$ chown -R root:root /*
But I have no permission for this operation. If i use command
$ sudo chown -R root:root /*
sudo: effective uid is not 0, is sudo installed setuid root?
What should I do to fix that?
Uh... that's an interesting situation. sudo requires the binary to be owned by root and have the setuid flag on it to function properly (this allows it to execute as the file owner, no matter who actually launched it).
By changing the owner, sudo can no longer run as root, and subsequently, can't run your commands as root.
The easiest method to recover from this is to
As you found out, there are a number of system files which absolutely depend on having the correct owner and the correct permissions. SSHd for example, will refuse to start if the host private key does not have exactly correct permissions (0600 and owned by root I think). sudo cannot elevate itself without being setuid and owned by root, and I'm sure there are many other security-related programs that won't operate if they see that things aren't perfect.
Through a lot of very tedious work, it would be possible to recover some of the permissions using an external computer, but it's not a fun task and a reinstall is probably going to be much simpler.
if you chown'd recursively before, then your permissions are more-than-likely irreversibly damaged.
Backup your data and reinstall.
Seriously, rebuild from scratch. even if you get past the error you are looking at, and manage to re-chown root, your system will still be as broken as it is now. there is effectively no means to recover from an out of control chowning (or chmoding for that matter). Even if you were somehow able to get a partial list of the original owners for each object, it would almost certainly be incomplete, and would reflect a stock system state, which may have been changed by app/daemon install after the files were initially created.
My IMac died (power supply issue, out of warranty) and I removed the HDD so I could recover some files. I'm trying to copy files from my Desktop folder on the Mac HDD using Ubuntu 10.04 (running from the CD-ROM), but I get access denied errors when I try to cd or ls into the directory because I'm not the owner.
I tried running chown -R Desktop but I get an error saying that the file system is read-only.
chown -R Desktop
Is there some way I can make the drive read/write or access the files without changing the owner?
The write support for some foreign filesystems in Linux is buggy so turned off by default. This may be why your Mac filesystem was mounted read-only.
If this is a one-off data recovery, just do it as root.
For some filesystems, you can specify that everything should be world-readable, or that every file should be owned by a particular user. First determine the volume and mount point of the Mac filesystem with the command df . in the Desktop directory; this displays something like
/dev/sdb4 123456 78901 23456 42% /media/disk1
Make sure no process is using the Mac filesystem (this includes any shell that has its working directory on it), and run
mount -o umask=022 /dev/sdb4 /media/disk1
umask=022 means that everyone can read everything. You could also use uid=ktrauberman (replace ktrauberman by your user name) so that every file is owned by you.
Try unmounting the filesystem and then remounting it from the command line with the -w option
mount -w /dev/sbd4 /mnt/macdrive
mount -w /dev/sbd4 /mnt/macdrive