1

I am logged under 'achille' achille belongs to 2 groups:

groups achille 
achille: achille users 

I want to change the group owner of file 'tree.test' to group 'users'

ls -l tree.test
-rw-r--r--. 1 achille achille 2512881 Dec  1 11:53 tree.test

I have got full control over my home dir:

ls -ld $HOME
drwx------. 15 achille achille 4096 Dec 10 11:51 /home/achille

I try:

chown :users tree.test
chown: changing group of 'tree.test': Operation not permitted

I try:

chgrp users tree.test
chgrp: changing group of 'tree.test': Operation not permitted

ok, so I decide to have as primary group the group 'users'

usermod command is available to achille, so I use it (right?):

usermod -g users achille

usermod: Permission denied.

usermod: cannot lock /etc/passwd; try again later

I log as root to perform this operation (changing primary group)

su - 

password:

then

usermod -g users achille

and check it out:

id -gn achille 
users

then ctrl + D to log back to achille

the file finally belongs to groups 'users' but the result is bad because my home dir and all files/dirs inside also belong to group users.

I finally found a way (without beeing logged as root) with newgrp command:

newgrp users

id -gn 

users

touch file0

file0 will have users as group owner

but it looks like newgrp works as long as achille belongs to the group you want to change to otherwise you 've got this error message:

newgrp games 

Password: (what password to put here?)

newgrp: failed to crypt password with previous salt: Invalid argument ????

so now I am just wondering (and asking), if chgrp,chown,usermod are worth keeping in tools bag beeing an unprivileged user. thanx folks!

  • In what directory is your tree.test file located and what are the permissions and ownerships of that directory? If it's in your home directory, you also seem to have some sort of extended attribute set on it (the final . in the permission string). – Kusalananda Dec 10 '19 at 18:55
  • in /home/achille; perm = 700 as stated, file has 644 perm. – achille Dec 10 '19 at 19:15
  • What is the result of lsattr tree.test? (by the way, you can change the group of a file you own to anyone of your groups, unless you are using extended attributes OR the filesystem you are working on does not allow it). – Eduardo Trápani Dec 10 '19 at 20:36
  • Please add output of groups no arguments. – ctrl-alt-delor Dec 10 '19 at 22:33
  • These are admin tools pretty explicitly. A user doesn't assign groups to themselves. As an example if a user could assign themselves to wheel they'd gain root privileges through sudo on many systems. These days it's so easy to set up a personal linux box or VM running linux that there's no reason not to learn the admin tools. – davolfman Dec 10 '19 at 22:47
1

Probably this

The problem

When you add a user to a new group, it just writes some data to a configuration file on the disk. Existing processes are not changed.

How to solve the problem.

You can logout and back in again, or use newgrp to create a new shell process with the new group added (this does the permission checks by reading the data in the file, and then starts a new shell in a new process, with the new group added to the groups).

  • @archie your comment is in the wrong thread. You have commented to the answer. – ctrl-alt-delor Dec 11 '19 at 11:52

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.