# How do I restore permissions of my files?

I ran the command sudo chown -R $(whoami)$(npm config get prefix)/{lib/node_modules,bin,share} and it changed the ownership of /usr/bin/sudo. I know it's stupid I was so sleepy I thought $(npm config get prefix) was not /usr. After that sudo so failed. I fixed it by running chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo as a root. My question is how should I restore the ownership of all files under /usr/? I am guessing it affected all the files under /usr/. Who owns all the files under /usr/? Doing sudo ls - /usr here's the output: dr-xr-xr-x. 2 myusername root 57344 Oct 15 11:11 bin drwxr-xr-x. 2 root root 4096 Feb 4 2016 games drwxr-xr-x. 49 root root 4096 Oct 12 19:54 include dr-xr-xr-x. 74 root root 20480 Oct 15 11:11 lib dr-xr-xr-x. 170 root root 118784 Oct 15 11:11 lib64 drwxr-xr-x. 44 root root 12288 Oct 15 11:11 libexec drwxr-xr-x. 13 root root 4096 Sep 3 22:21 local dr-xr-xr-x. 2 root root 20480 Oct 12 07:45 sbin drwxr-xr-x. 296 myusername root 12288 Oct 12 19:56 share drwxr-xr-x. 4 root root 4096 Sep 24 07:30 src lrwxrwxrwx. 1 root root 10 Feb 4 2016 tmp -> ../var/tmp  I'm a linux newbie, pls be elaborate with your answer, thanks! edit retag close merge delete ## 3 Answers Sort by » oldest newest most voted Please keep in mind, running these commands might mess up your system and you may lose all your data. Make a backup of everything right away before attempting anything further. If you choose to follow any of my advice below, you do so AT YOUR OWN RISK. It looks like most files under /usr are still owned by root, so you do not need to mess with most of /usr. It seems like you actually ran chown on: • /usr/lib/node_modules • /usr/bin • /usr/share Taking a look at the chown man page (accessible via $ man chown) you will see the -R flag:

-R, --recursive
operate on files and directories recursively


So to chown every file under /path/to/directory to be owned by user and to be part of group, you would run:

# chown -R user:group /path/to/directory


Of course, the question is, were all the files in those directories owned by root before your ran the command in the first place.

Running the find command on my Fedora 24 system looking for any file or directory in /usr/bin and /usr/share that is not owned by root (I don't have a /usr/lib/node_modules directory because I don't have Node installed), I get these results:

# find /usr/bin /usr/share \! -user root -print
/usr/share/polkit-1/rules.d


That means the only file or directory that is not owned by root in these two directories on my system is the directory /usr/share/polkit-1/rules.d. Of course, there is no guarantee your system should be the same.

The directory /usr/share/polkit-1/rules.d should be owned by user polkitd, as you can see here:

# ls -l /usr/share/polkit-1/
total 8
drwxr-xr-x. 2 root    root 4096 Oct 15 18:36 actions
drwx------. 2 polkitd root 4096 Oct 15 18:25 rules.d


(There are files under /usr/share/polkit-1/rules.d but they are owned by root.)

So, assuming your /usr/bin and /usr/share were the same as mine in terms of file permissions (which, again, may not be true), reversing your original command could be done via:

# chown -R root /usr/bin
# chown -R root /usr/share
# chown polkitd /usr/share/polkit-1/rules.d


Notice that I am using # chown -R root /usr/bin and NOT # chown -R root:root /usr/bin. The second root in the command refers to the group. In your original command you did not modify the groups so there is no need to reverse group ownership.

I can't say anything about the original ownership of /usr/lib/node_modules so I'm skipping that.

Good luck!

more

thank you!

( 2016-10-16 02:08:21 -0600 )edit
ls -l /usr/bin/sudo
---s--x--x. 1 root root 140K 21. Sep 18:14 /usr/bin/sudo


=> chmod 4111 /usr/bin/sudo !!!

please read:
man rpm
rpm -Va
rpm --setperms
rpm --setugids

and here:
http://www.cyberciti.biz/tips/reset-rhel-centos-fedora-package-file-permission.html

more

You can search for the packages in all involved directories with sudo rpm -qf /usr/*. Sort the output uniqueness (sort -u).

RPM syntax to fix file ownership.
To set user/group ownership of files in a package, enter:

sudo rpm --setugids {packagename}


Loop on all concerned package and run this command.

- it will change ownership of all files of the package. For example also in /var.
- maybe there are files that are not installed with a rpm package. For example an applcation installed with make install

FYI: you can also restore the file permission with the command : sudo rpm --setperms {packagename}

more

## Stats

Asked: 2016-10-15 20:52:35 -0600

Seen: 1,134 times

Last updated: Oct 16 '16