The official Red Hat System Administration I RH124 says:

root can grant ownership to any group, while non-root users can grant ownership only to groups they belong to

[student@web ~]$ id student
uid=1000(student) gid=1000(student) groups=1000(student),1009(dtracy)
[student@web ~]$ grep bboop /etc/passwd
[student@web ~]$
[student@web ~]$ usermod -G student bboop
-bash: /usr/sbin/usermod: Permission denied
[student@web ~]$ su -c 'usermod -G student bboop'
[student@web ~]$ grep student /etc/group

So why can't I add user bboop to users student primary student group as user student but need to elevate permissions to root or is it simply me misunderstanding or is it a bug ?

  • Can you add the complete sentence/paragraph for that context? It's a little vague in its current form. – Haxiel Dec 2 '18 at 11:03

The "grant ownership" in your quote refers to ownership of the file, with the chown or chgrp command.

What you are trying to do has nothing to do with ownership, it is about membership. Just because a regular user is member of a group doesn't mean the he can add any other user to this group. Assigning users to groups is an administrative task that requires root privileges.

Also note that the error message "bash: /usr/sbin/usermod: Permission denied" indicates that the usermod binary doesn't even have execute permissions for regular users. It wouldn't work anyway without write access to /etc/passwd or /etc/group, but it would be able to give a better error message.

  • Yes, indeed. But the line while non-root users can grant ownership only to groups they belong to refers only to given users primary group, correct? I mean I cannot assign a supplementary group to a file even if I'm a member of that supplementary group. – blabla_trace Dec 2 '18 at 11:23
  • No, you can grant group ownership of any group you're a member of, to any file you actually own. The primary group is just the group to which the files you create get assigned to by default. In your example, the student user might use touch /tmp/testfile to create a file with owner student, group student, and then use chgrp dtracy /tmp/testfile to change the ownership to owner student, group dtracy. – telcoM Dec 2 '18 at 14:23

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.