LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   chgrp: operation not permitted even though I own the file! (https://www.linuxquestions.org/questions/linux-newbie-8/chgrp-operation-not-permitted-even-though-i-own-the-file-118678/)

the theorist 11-21-2003 06:59 PM

chgrp: operation not permitted even though I own the file!
 
I want to chgrp a file (from my default user group) to another group of which I'm a member. So:
Code:

$ chgrp <newgroup>  <file that I own>
chgrp: changing group of '<file that I own>': Operation not permitted

Why can't I change it?
Interstingly, root can change the group, and then the regular user can change it back to the user's default group.

I'm using Red Hat 7.2 on a ext3 file system.

chup 11-21-2003 07:04 PM

tried chown?

the theorist 11-21-2003 07:14 PM

chup:
Yes; the error occurs if I try:
Code:

chown <same user>:<new group> <file that I own>
on a file that I both own and is in my default user group. Also if I just try to change the user.
(I'm assuming that I can't chown on a file I don't own... so I didn't test that!)

tearinox 11-21-2003 07:16 PM

CHOWN SYNTAX = chown [options] user[:group] file...

CHGRP SYNTAX = chgrp [options] group file...

Chown does what chgrp can, plus its older so you know it will work better.
Note, that was right from the manual pages you should be reading =P

tearinox 11-21-2003 07:17 PM

type ls -l so we can see the file

darthtux 11-21-2003 07:30 PM

To change the group ownership of a file to another group you have to be a member of that group or root. That is why you are getting the Operation not permitted error.

the theorist 11-21-2003 07:35 PM

tearinox: That's what I'm doing (with no [options]); I've been over the man pages several times other web pages several times. I'm pretty sure the syntax is right.

Here's an explicit example: (my username is "will" and I want to change to group "ezra")
Code:

[20:30:47][will][0]$ ls -l testfile
-rw-rw-r--    1 will    will          20 Nov 21 20:30 testfile
[20:30:54][will][0]$ chgrp ezra testfile
chgrp: changing group of `testfile': Operation not permitted


the theorist 11-21-2003 07:42 PM

darthtux:
I'm a member of the group. This is the last line of /etc/group:
Code:

ezra:x:504:will,sam
In any case, I can change the group membership of testfile back to "will", after root has changed it to "ezra". So I think the system recognizes I'm in the target group.

I posted in the newbie forum because I figured it was something common but not obvious; I'm not an idiot (most of the time).

darthtux 11-21-2003 07:44 PM

What about
chown will.ezra file

the theorist 11-21-2003 08:10 PM

darthtux:
Nope, same "operation not permitted result".

Thanks for everyone's comments. I'm starting to think its something uniquely screwy with my RedHat 7.2 installation. (Although, otherwise, I haven't had problems with it.) I'll try it out on another system and report back later.
If anyone has any weird ideas, feel free to tell me!

the theorist 11-22-2003 03:24 PM

I found the same results on my RedHat 9.0 system, too. Weird.

the theorist 11-24-2003 08:28 AM

Apparently I needed to reboot (on both 7.2 and 9.0) to get the system to fully (?) recognize the new group settings. I added the group "ezra" with groupadd, and then manually edited /etc/group to put user "will" in group "ezra". Rebooting let me change the group permission, as sought above.

Perhaps I should have used "usermod -G ezra will" to do this.

scraimer 08-22-2006 02:14 AM

Groups updating
 
Groups don't update until you log-in again. So even if you edit /etc/groups, you still have to logout and log in again (or just run another shell inside the current one. That should give the same effect :-)

DaveQB 12-30-2006 03:20 AM

This had me stumpped too and I have been using Linux for years, both server and desktop.

You do need to login again.

scraimer running 'bash' and then trying to chgrp again doesn't work either, unfortunately.

iggi 11-27-2007 09:10 AM

You can also use
Code:

newgrp <group>
to change to the group without a restart/logout (actually changes your primary group to <group>).

What I was wondering: why do you have to be part of the group <target> in order to be able to change the current group ownership to <target>? Some kind of a security mechanism which I'm overlooking?


All times are GMT -5. The time now is 06:16 PM.