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

ukdjmx9f  于 2022-11-02  发布在  Linux
关注(0)|答案(7)|浏览(131)

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

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
cwtwac6a

cwtwac6a1#

您是否在更改组后注销并重新登录?请参阅:
Super User answer involving touch permissions failure

iswrvxsc

iswrvxsc2#

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

希望能有所帮助。)

fgw7neuy

fgw7neuy3#

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

什么?我做的都对了为什么不管用?

答案:

完全重新启动计算机。停止终端不足以解决这些问题。
我认为apache 2也使用了www-data组,所以这个任务在某种程度上阻止了用户和组的正确执行。你不仅要注销,而且要停止并重新启动使用你的组的任何服务。如果重新启动没有得到它,你就有更大的问题了。

ppcbkaq5

ppcbkaq54#

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

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

这将设置目录的活动权限和在中创建的任何内容的默认权限。
如果您刚刚将自己添加到staff组,则在不重新登录的情况下,此操作将无法工作,但您可以仅为自己设置当前会话的权限。

uklbhaso

uklbhaso5#

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

e0bqpujr

e0bqpujr6#

也许你的硬盘已经满了。使用这个命令来检查“/dev/...”行。

df -h

nukf8bse

nukf8bse7#

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

sudo chmod -R 777 /yourDir/file.log

相关问题