Linux,为什么我有组权限却不能写?

发布于 2024-10-18 08:54:53 字数 424 浏览 2 评论 0原文

我想在我所属的员工组拥有的目录中创建一个文件。为什么我不能这样做?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

定格我的天空 2024-10-25 08:54:53

您在进行组更改后是否注销并重新登录?请参阅:
涉及触摸权限失败的超级用户答案

Did you logout and log back in after making the group changes? See:
Super User answer involving touch permissions failure

烙印 2024-10-25 08:54:53

我遇到了同样的问题,检查该文件夹是否有更多 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

再次检查权限:

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

希望有帮助。 ;)

I had the same issue, check if the folder has any more ACL rules or not!

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.

The solution is what @techtonik said, add write permission for user:

[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. ;)

静谧幽蓝 2024-10-25 08:54:53

为什么 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"

什么?我已经做了所有正确的事情,为什么它不起作用?

答案:

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

我认为 apache2 也使用 www-data 组,因此该任务在某种程度上阻止了用户和组的正确执行。您不仅必须注销,还必须停止并重新启动使用您的组的任何服务。如果重新启动后仍无法解决问题,那么您就会遇到更大的问题。

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.

风启觞 2024-10-25 08:54:53

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

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

它设置目录的活动权限和其中创建的任何内容的默认权限。

如果您刚刚将自己添加到 staff 组,则在不重新登录的情况下此操作将无法工作,但您可以仅为自己设置当前会话的权限。

Use Linux ACL (access control lists) - it is more fine-grained version of permission system,

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.

倾城月光淡如水﹏ 2024-10-25 08:54:53

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

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.

时光磨忆 2024-10-25 08:54:53

也许你的硬盘已满。使用此命令查看“/dev/...”行。

df -h

输入图片此处描述

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

df -h

enter image description here

静谧幽蓝 2024-10-25 08:54:53

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

sudo chmod -R 777 /yourDir/file.log

Check if your parent directory have permission before you add content to that file

sudo chmod -R 777 /yourDir/file.log
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文