Linux,为什么即使我有组权限也不能写入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5054888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux, Why can't I write even though I have group permissions?
提问by Ben McCann
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
采纳答案by AdamJonR
Did you logout and log back in after making the group changes? See:
Super User answer involving touch permissions failure
您是否在更改组后注销并重新登录?请参阅:
涉及触摸权限失败的超级用户答案
回答by Eric Leschinski
Why can't Linux user edit files in group he is a part of?
为什么 Linux 用户不能在他所在的组中编辑文件?
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:
我正在使用 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
Restart the terminal now to ensure the users and groups have taken effect. Login as el.
现在重启终端,确保用户和组生效。以 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.
我认为发生的情况是 apache2 也使用 www-data 组,因此该任务以某种方式阻止了用户和组的正确执行。您不仅必须注销,还必须停止并重新启动使用您的组的任何服务。如果重新启动没有得到它,你有更大的问题。
回答by Kolyunya
I had an issue when a user could not access the /foo/bar/baz
directory even when he had permissions because he did not have an access to the bar
directory.
我遇到了一个问题,即用户/foo/bar/baz
即使有权限也无法访问该目录,因为他无权访问该bar
目录。
回答by anatoly techtonik
Use Linux ACL (access control lists) - it is more fine-grained version of permission system,
使用 Linux ACL(访问控制列表)——它是权限系统的更细粒度版本,
setfacl -R -m 'group:staff:rwx' -m 'd:group:staff:rwx' /usr/local/lib/R/
This sets both active rights for directory and default rights for anything created within.
这将设置目录的活动权限和在其中创建的任何内容的默认权限。
This fails to work without relogin if you've just added yourself to the staff
group, but you may set the permission only for yourself for the current session.
如果您刚刚将自己添加到staff
组中,则在没有重新登录的情况下这将无法工作,但是您可以仅为自己设置当前会话的权限。
回答by Laszlo Lugosi
I had the same issue, check if the folder has any more ACL rules or not!
我有同样的问题,检查文件夹是否有更多的 ACL 规则!
If you can see + (plus sign) when you list folder, that means it has special access rules. For example:
如果您在列出文件夹时可以看到 +(加号),则表示它具有特殊的访问规则。例如:
[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
View the permission:
查看权限:
[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
So that means my user (user_in_apache_group) has no write permission for that folder.
所以这意味着我的用户(user_in_apache_group)对该文件夹没有写权限。
The solution is what @techtonik said, add write permission for user:
解决方案是@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
...
Hope it helps. ;)
希望能帮助到你。;)
回答by Mani P
Check if your parent directory have permission before you add content to that file
在向该文件添加内容之前检查您的父目录是否具有权限
sudo chmod -R 777 /yourDir/file.log