Linux, Why can't I write even though I have group permissions?

前端 未结 6 1536
醉酒成梦
醉酒成梦 2021-01-30 12:30

I want to create a file in a directory owned by the staff group which I am a member of. Why can I not do this?

bmccann@bmccann-htpc:~$ ls -l /usr/local/lib/R/
t         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 12:38

    Why can't Linux user edit files in group he is a part of?

    I am using Ubuntu 12.04 and had the same problem where a user cannot write to a file to whom he is allowed group access to. For example:

    whoami                                        //I am user el
      el                                            
    
    touch /foobar/test_file                       //make a new file
    
    sudo chown root:www-data /foobar/test_file    //User=root  group=www-data
    
    sudo chmod 474 /foobar/test_file              //owner and others get only read, 
                                                  //group gets rwx
    
    
    sudo groupadd www-data                        //create group called www-data    
    
    groups                                        //take a look at the groups and see
     www-data                                     //www-data exists.
    
    groups el                                     //see that el is part of www-data
      el : www-data                               
    

    Restart the terminal now to ensure the users and groups have taken effect. Login as el.

    vi /foobar/test_file                          //try to edit the file.
    

    Produces the Warning:

    Warning: W10: Warning: Changing a readonly file"
    

    What? I've done everything right why doesn't it work?

    Answer:

    Do a full reboot of the computer. Stopping the terminal isn't enough to fix these problems.

    I think what happens is apache2 also uses the www-data group, so the task was somehow preventing the users and groups from being enforced correctly. Not only do you have to logout, but you have to stop and restart any services that use your group. If a reboot doesn't get it, you've got bigger problems.

提交回复
热议问题