linux – 为所有用户设置umask

我正在尝试将所有用户认umask设置为002,包括我的CentOS框上的root.

根据this和其他答案,这可以通过编辑/ etc / profile来实现.但是该文件顶部的评论说:

It’s NOT a good idea to change this file unless you kNow what you
are doing. It’s much better to create a custom.sh shell script in
/etc/profile.d/ to make custom changes to your environment,as this
will prevent the need for merging in future updates.

所以我继续创建了以下文件
/etc/profile.d/myapp.sh
单行:

umask 002

现在,当我创建一个以root身份登录文件时,该文件具有664权限,就像我希望的那样.但是我的Apache mod_wsgi应用程序创建的文件,或者用sudo创建的文件,仍认为644权限……

$touch newfile(以root身份):
结果= 664(工程)

$sudo touch newfile:
结果= 644(不起作用)

Apache mod_wsgi app创建的文件
结果= 644(不起作用)

Python的RotatingFileHandler创建的文件
结果= 644(不起作用)

为什么会发生这种情况,如何在系统范围内确保664文件权限,无论创建文件的是什么?

解决方法

profile是shell的启动文件.在profile.d中设置umask 002可以为从登录shell启动其进程的所有用户设置它.

你的两个例子是不同的.对于Apache,您可以在启动http服务器的init.d脚本中设置umask.

对于使用sudo启动的进程,您可以在sudoers文件中使用umask选项.

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...