为什么要使用 umask? [英] Why would you use umask?

查看:43
本文介绍了为什么要使用 umask?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一些源代码,我在主程序的最开始发现了这个语句:

I am reading some source code and I found this statement at the very beginning of the main routine:

umask(077);

这可能是什么原因?

手册页 (man 2 umask) 指出:

The man page (man 2 umask) states:

umask -- 设置文件创建模式掩码

umask -- set file creation mode mask

这种清算允许每个用户限制对他的默认访问文件

This clearing allows each user to restrict the default access to his files

但我不清楚为什么会有人这样做?作为快捷方式?

But is not clear to me why would anyone do that? as a shortcut ?

推荐答案

设置 umask(077) 确保程序创建的任何文件只能对其所有者访问(第一个位置为 0 =所有可能可用的权限),没有其他人(第二/第三位置 7 = 不允许组/其他的所有权限).

Setting umask(077) ensures that any files created by the program will only be accessible to their owner (0 in first position = all permissions potentially available) and nobody else (7 in second/third position = all permissions disallowed to group/other).

这篇关于为什么要使用 umask?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆