查看和设置 Linux 默认权限掩码 umask
决定每个新建文件开放程度的八进制掩码——`umask` 查看当前值,`umask 027` 为当前 shell 收紧它。
直接运行 `umask` 打印当前掩码,执行 `umask 027` 后新文件权限为 640、新目录为 750。
01命令
命令
$ umask 02702作用说明
umask 会在创建文件时从请求的权限里按位清除:掩码为 027 时,文件变成 640(rw-r-----),目录变成 750——组内可读,其他人完全无权限。它是进程级且可继承的,一次性 `umask 027` 只影响当前 shell;想长期生效需写入 ~/.bashrc、/etc/profile 或 PAM 的 umask 配置。不想改动当前 shell 的话,用 `(umask 027; touch secret.txt)` 在子 shell 里创建。
03风险
!注意: chmod 修的是已有文件,umask 管的是未来文件——改 umask 不会追溯改变磁盘上已有的任何文件。
04撤销
撤销
$ umask 02205来源
- umask(2) — set file mode creation mask依据: Explains that umask bits are cleared from requested permissions when files are created, and that the mask is inherited by children.
最后验证: 2026-09-17 · 分类: 安全与隐私