chgrp: operation not permitted even though I own the file!
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!)
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.
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
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:
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!
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.
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 :-)
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.