72

I am having an access problem to some files and directories that I have tracked down to the group assigned to access them.

When I manually change the name of the group in the properties/permissions menu for a directory from the default setting (MyGroup) to www-data used by my Drupal Website, the directory error messages I get are gone.

There are a large number of files and directories that require this change. If believe using chmod will change the owner which is set correctly and being new to Ubuntu, I am reluctant to experiment without a better understanding of how owner and groups work in the permissions settings.

What command changes the Group setting for a directory?

3 Answers 3

117

chmod does not change owner. It changes permissions. chown changes owner (and group if need be) and chgrp changes group.

You can use

chown {-R} [user]{:group} [file|directory]

to set user and group ownership where -R does everything that is inside directory. So sudo chown -R rinzwind:rinzwind /tmp/ would set /tmp/ and everything in it to user rinzwind and group rinzwind.

There is also

chgrp {-R} [group] [file|directory]

if you do not need to touch the user permissions and only need to set the group.

Oh and you can check what group a user belongs to with groups {username}.

1
  • I get permissions issue
    – STF
    Nov 12, 2023 at 9:23
23

In addition to Rinzwind's answer, you might also use chown :group [file|directory] to change the group only and leave the owner intact.

2
  • That's what Rinzwind's answer already says though not as clearly. I guess your answer is not a duplicate then. Jan 15, 2017 at 22:46
  • This wasn't obvious at all from Rinzwind's answer, so this one helps, actually Dec 11, 2019 at 12:39
2

To change group to current user, use this:

sudo chgrp -R $USER ~/.blabla
2
  • 1
    For me, this was a helpful addition, specifying the $USER variable to set it to the current user. Probably widely known for many Ubuntu users, but being new to it myself, I appreciated this person's contribution.
    – McHobbes
    Dec 3, 2019 at 18:23
  • 1
    @McHobbes thx. At least I helped one person :)
    – otto
    Dec 3, 2019 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .