6

Some one messed up /usr/local/ permissions, so that nobody else can access it. Now I would like to duplicate user permissions to group permissions, since chmod g+rx -R /usr/local is unsafe. How should this be done?

Using linux (ubuntu 10.04).

TiansHUo
  • 175
  • 8

3 Answers3

14

You can copy permissions:

chmod -R g=u /usr/local

This will copy the user permissions to the group permissions.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
1
cd /usr/local
chmod -R g-rwx .
find . -perm -u+r -exec chmod g+r {} \;
find . -perm -u+w -exec chmod g+w {} \;
find . -perm -u+x -exec chmod g+x {} \;

This first clears the group permissions from all files. Then it should search down, examining each file for each of the three user permission bits in turn (r, w, x). For each permission, when it finds a file that has that bit set (disregarding their other user permission bits), it sets the equivalent group bit on for that file.

I strongly advise you to test this on a random subdirectory first, preferably with some corner-case files in it that you make yourself. But it works in my comparable tests.

MadHatter
  • 79,770
  • 20
  • 184
  • 232
0

i did find this perl based solution on the net also.

find . | perl -ne 'chomp; $a = (stat $_)[2] & 07777; $a = ($a & 07707) | (($a >> 3) & 070); chmod($a, $_)'

but the

    chmod g=u

mentioned elsewhere is better i think

ShoeLace
  • 151
  • 1
  • 8