1

I am currently preparing for LPIC Level 1 exam and I have been practicing management of user accounts on CentOS 7 system installed on VirtualBox.

Firstly, as root, I created a user 'foo' with group 'bar' and practiced changing file permissions. Then I created a new group 'somegroup' and added user 'foo' to it. Then I removed user 'foo' from group 'bar'. (Kindly note that I used 'groupmems' command for this.)

Then I logged into foo's account and used 'touch' command for creating a file in foo's ~/Documents directory and then checked its file permissions with 'ls -l' command. I was expecting that the new file would show file ownership as belonging to 'foo somegroup' but strangely I found that the group ownership was still with group 'bar'.

Clearly I'm missing some basic knowledge here. Please help me in understanding this. (I'm sorry if I've been a bit too verbose.)

  • I'm not familiar with the groupmems command. What does it do? What is the output of getent passwd foo? What about ls -ld ~foo/Documents? – Gilles 'SO- stop being evil' Mar 23 '16 at 22:19
2

That's because the parent directory belongs to the old group. On many systems files and directories's default group owner is their parent directory. If you want that to stop, you have to change the group owner of the parent directory. Then you can change the group owner of all its child directories using:

chgrp -R desiredgroup parentdirectory

The -R option makes it apply to all its children.

0

changing group for a user will not change already assign group.

~/Documents's group in foo's is still bar.

new file will inherit group ownship of parent dir.

changing group on file is done by chgrp newgroup on a file or directory.

  • So how do I change foo's directories to somegroup too? Will changing the primary group of user 'foo' with 'usermod -g somegroup foo' do the trick? – Sachin Borkar Mar 23 '16 at 13:27
  • 1
    The ownership of files beneath a directory are only inherited when the s bit is set for the group on that specific folder, which by default isn't set. Normally the group which is first listed when executing groups, will be used for the group ownership. You can change the "primary" group with newgrg <group-name> once, as long as the user belongs to that group. – Thomas Mar 23 '16 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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