【问题标题】:linux file permissions as user cannot access filelinux文件权限,因为用户无法访问文件
【发布时间】:2020-07-02 23:16:45
【问题描述】:

我似乎无法打开应该属于我的文件...我觉得很傻,有点像我疯了,我不知道出了什么问题...但我一定是错过了什么。

# Example shows that all files in directory are owned by user2 with 664 permission
$ ls -la /home/user1/filestore

total 2788
drw-rw-r--    2 user2     user2   2    0480 Jul  2 12:44 .
drwxrwxr-x 8558 user1     user1     2494464 Jul  1 16:28 ..
-rw-rw-r--    1 user2     user2     23718 Jul  1 15:02 z6B00001-1593640926.readings
-rw-rw-r--    1 user2     user2     73606 Jul  2 12:44 z6B00001-1593719061.readings
-rw-rw-r--    1 user2     user2     232629 Jul  2 14:44 z6B00001-1593719062.readings

# showing current user
$ whoami
user1

# groups for current user
$ groups user1
user1 user2

# groups for user2
$ groups user2
user2 user1

# start python as user2
$ sudo -u user2 python
>>> open("/home/user1/filestore/z6B00001-1593640926.readings","rb") as f:
...     f.read()
Traceback (most recent call last): #<<< what??????????
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: '/home/user1/filestore/z6B00001-1593719062.readings'
>>> os.system("whoami")
user2
0
>>> os.system("groups")
user2 user1
0
>>> os.system("ls -la /home/user1/filestore")
ls: cannot access '/home/user1/filestore/.': Permission denied
ls: cannot access '/home/user1/filestore/..': Permission denied
ls: cannot access '/home/user1/filestore/z6B00001-1593640926.readings': Permission denied
ls: cannot access '/home/user1/filestore/z6B00001-1593719061.readings': Permission denied
ls: cannot access '/home/user1/filestore/z6B00001-1593719062.readings': Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
-????????? ? ? ? ?            ? z6B00001-1593640926.readings
-????????? ? ? ? ?            ? z6B00001-1593719061.readings
-????????? ? ? ? ?            ? z6B00001-1593719062.readings
256

>>> exit()

$ sudo -u user1 python
>>> open("/home/user1/filestore/z6B00001-1593640926.readings","rb") as f:
...     f.read()
Traceback (most recent call last): #<<< what??????????
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: '/home/user1/filestore/z6B00001-1593719062.readings'
>>> os.system("whoami")
user1
0
>>> os.system("groups")
user1 user2
0

预期的行为是能够以用户 1 或用户 2 的身份打开和读取(和写入)这些文件......目前两者都不起作用:(

【问题讨论】:

  • 如果您尝试在 python 之外读取文件,结果是什么? (例如,用md5sum /home/user1/filestore/z6B00001-1593640926.readings 计算它的校验和)
  • 同样的错误(当使用任何一个用户配置文件时......如果我是 root,它非常高兴)......我想也许我只是想通了......我认为目录需要 x 标志。 ..也许
  • 是的,我觉得很傻......我不知道目录需要执行权限:(显示我对 linux 了解多少
  • Sooo ...首先让我印象深刻的是/home/user1/filestore/home/sbsu/store/z6B00001之间的差异...该文件系统是如何安装的,它是如何进入/home/user1的?
  • 啊,我试图掩盖我的真实路径并错过了一个:P(已修复)

标签: linux permissions filesystems


【解决方案1】:

我觉得特别傻......显然目录需要设置执行位,我不知道

通过chmod 775 /home/user1/filestore解决

对不起,我发布了一个问题,然后自己回答了......但我要离开它,因为我在 2 分钟的搜索中没有看到一个骗子:P 如果存在这样的骗子,请随时指向一个骗子并关闭,或者给出比这个更彻底的答案

【讨论】:

    猜你喜欢
    • 2012-11-01
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    相关资源
    最近更新 更多