linux 文件权限,因为用户无法访问文件
linux file permissions as user cannot access file
我似乎无法打开本应归我所有的文件...我觉得很傻,有点失去理智,我不知道出了什么问题...但我一定是错过了东西。
# 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
预期的行为是能够以 user1 或 user2 的身份打开和读取(和写入)这些文件……目前两者都不起作用:(
我觉得特别傻...显然该目录需要设置执行位,而我不知道
已通过 chmod 775 /home/user1/filestore
解决
抱歉,我发布了一个问题,然后自己回答了...但我要离开它,因为我在 2 分钟的搜索中没有看到一个骗子:P 随时指向一个骗子,如果这样的话就关闭dupe 存在,或者给出比这个更彻底的答案
我似乎无法打开本应归我所有的文件...我觉得很傻,有点失去理智,我不知道出了什么问题...但我一定是错过了东西。
# 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
预期的行为是能够以 user1 或 user2 的身份打开和读取(和写入)这些文件……目前两者都不起作用:(
我觉得特别傻...显然该目录需要设置执行位,而我不知道
已通过 chmod 775 /home/user1/filestore
抱歉,我发布了一个问题,然后自己回答了...但我要离开它,因为我在 2 分钟的搜索中没有看到一个骗子:P 随时指向一个骗子,如果这样的话就关闭dupe 存在,或者给出比这个更彻底的答案