[英]How to automatically set permissions of future/new files in Ubuntu?
Currently, I do sudo chown -R ubuntu:ubuntu /home/ubuntu/<folder>
. 目前,我做sudo chown -R ubuntu:ubuntu /home/ubuntu/<folder>
。
But, when I run a Python script which would be creating a folder named testoutput
and write files to it, the folder is created with the root
permissions, and hence, getting permission denied
error while writing files to the folder. 但是,当我运行一个Python脚本创建一个名为testoutput
的文件夹testoutput
其写入文件时,该文件夹是使用root
权限创建的,因此在将文件写入文件夹时会获得permission denied
错误。
How do I ensure that even new files in the range get the same permissions when doing chown
? 如何确保在进行chown
时,即使是该范围内的新文件也能获得相同的权限? Is there a way to ensure that in Ubuntu? 有没有办法确保在Ubuntu中?
The permissions of the new folder i : 新文件夹i的权限:
drwxr-xr-x 2 root root
while the permission of the existing folders is: 而现有文件夹的权限是:
drwxrwxr-x 2 ubuntu ubuntu
In nearly all operating systems, the owner of a new file is determined by the user context from which the file is created. 在几乎所有操作系统中,新文件的所有者由创建文件的用户上下文确定。 Ie you are most likely running the repsective python script as root
. 也就是说,你最有可能以root
身份运行repsective python脚本。 If you recursively chown
the base directory testoutput
afterwards - as root
of course - you shuld be fine. 如果你之后以递归方式chown
基本目录testoutput
- 当然是root
- 你应该没问题。 If you do not want root
to be the initial owner, consider not running the respective script as root
in the first place, but as the desired owner. 如果您不希望root
成为初始所有者,请考虑不首先以root
身份运行相应的脚本,而是将其作为所需的所有者。 Alternatively have a look at ACLs . 或者看看ACL 。
This is governed by umask
setting which is set by default here to 这由umask
设置控制,默认设置在此处
root@brad:~# grep ^UMASK /etc/login.defs
UMASK 022
root@brad:~#
(though pam and other services for remote login etc pp have overrides). (虽然用于远程登录等的pam和其他服务有pp覆盖)。
With this we have: 有了这个,我们有:
root@brad:~# umask # four digits because of suid bit
0022
root@brad:~# mkdir tempDir1
root@brad:~# ls -ld tempDir1
drwxr-xr-x 2 root root 4096 Aug 17 07:22 tempDir1
root@brad:~# umask 002
root@brad:~# umask
0002
root@brad:~# mkdir tempDir2
root@brad:~# ls -ld tempDir?
drwxr-xr-x 2 root root 4096 Aug 17 07:22 tempDir1
drwxrwxr-x 2 root root 4096 Aug 17 07:22 tempDir2
root@brad:~#
And you see how changing the middle digit from 022 to 002 made the group permission writeable. 并且您看到如何将中间数字从022更改为002使得组权限可写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.