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

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/
total 4
drwxrwsr-x 2 root staff 4096 2010-07-31 16:21 site-library
bmccann@bmccann-htpc:~$ id -nG bmccann
bmccann adm dialout cdrom plugdev staff lpadmin admin sambashare
bmccann@bmccann-htpc:~$ touch /usr/local/lib/R/site-library/tmp
touch: cannot touch `/usr/local/lib/R/site-library/tmp': Permission denied
104935 次浏览

更改组后是否注销并重新登录? 参见:
超级用户答案涉及触摸权限失败

为什么 Linux 用户不能在他所属的组中编辑文件?

我正在使用 Ubuntu 12.04,遇到了同样的问题,用户无法写入一个允许他组访问的文件。例如:

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

现在重新启动终端,以确保用户 和团队已经生效。登录为 el。

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

产生警告:

Warning: W10: Warning: Changing a readonly file"

什么? 我什么都做对了为什么不行?

回答:

完全重新启动计算机。停止终端不足以修复这些问题。

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.

当一个用户无法访问 /foo/bar/baz目录时,我遇到了一个问题,即使他有权限,因为他没有访问 bar目录。

使用 Linux ACL (访问控制列表)-它是权限系统的更细粒度的版本,

setfacl -R -m 'group:staff:rwx' -m 'd:group:staff:rwx' /usr/local/lib/R/

这同时设置了目录的活动权限和内部创建的任何内容的默认权限。

如果您刚刚将自己添加到 staff组,那么不重新登录就无法工作,但是您可以仅为自己设置当前会话的权限。

I had the same issue, 检查文件夹是否还有其他 ACL 规则!

如果在列表文件夹中可以看到 + (加号) ,这意味着它有特殊的访问规则。例如:

[user_in_apache_group@web02 html]$ ls -l
total 16
drwxrwxr-x  16 apache apache 4096 Sep  4 13:46 ilias
drwxrwxr-x+ 15 apache apache 4096 Sep  4 13:46 ilias5

查看权限:

[user_in_apache_group@web02 html] getfacl ilias5
# file: ilias5
# owner: apache
# group: apache
user::rwx
user:user_in_apache_group:r-x
group::rwx
mask::rwx
other::r-x

这意味着我的用户(user _ in _ apache _ group)对该文件夹没有写权限。

解决方案就是@techtonik 所说的,为用户添加写权限:

[user_in_apache_group@web02 html]$ sudo setfacl -m u:user_in_apache_group:rwx ./ilias5

Check permission again:

[user_in_apache_group@web02 html] getfacl ilias5
...
user:user_in_apache_group:rwx
...

希望能有所帮助

在向该文件添加内容之前,请检查父目录是否具有权限

sudo chmod -R 777 /yourDir/file.log

Maybe your hard disk is full. use this command to check out the "/dev/..." rows.

df -h

enter image description here