如何在 Ubuntu 17.04 中设置默认 umask?

G.W*_*.W. 6 permissions .profile umask gnome-session 17.04

过去,我一直设置umask~/.profile。我设置了一个umask077所以我的文件获得了600 (rw-------). 但是~/.profile在 Ubuntu 17.04 中将其设置为不再有效。

因此,当在 Ubuntu 17.04 上的 gnome 会话中创建新文档时,我可以在哪里配置以便使用权限 600 创建它们?

Too*_*ets 6

为任何用户创建的所有目录和文件设置权限:

  1. 须藤纳米 /etc/pam.d/common-session
  2. 找到带有“session optional pam_umask.so”的行
  3. 将此更改为“会话可选 pam_umask.so umask=0077”
  4. 保存文件。
  5. 重启。

新文件将为 600。新目录将为 700。

  • 除了 Daniel 的答案中链接到的默认 GNOME 终端中的错误外,这可行,但我很好奇您为什么建议直接修改 `/etc/pam.d/common-session`,因为该值主要是定义的在`/etc/login.defs`(至少从 18.04 开始 - 有没有改变)? (2认同)

Dan*_*iel 5

TL; dr:在文件中替换UMASK 022为eg ,但不能100%工作。UMASK 027/etc/login.defs

\n
\n

文档

\n

有关这方面的信息,请参阅手册页 (20.04) 。有几个地方可以设置它:我过去使用过/etc/pam.d/loginor但停止工作,所以现在我正在使用which部分工作。/etc/default/login/etc/login.defs

\n
\n

PAM 模块尝试按以下顺序从以下位置获取 umask 值:

\n

\xc2\xb7 umask= 用户 GECOS 字段中的条目

\n

\xc2\xb7 umask= 参数

\n

\xc2\xb7 /etc/login.defs 中的 UMASK 条目(受 /etc/login.defs 中的 USERGROUPS_ENAB 影响)

\n

\xc2\xb7 UMASK= /etc/default/login 中的条目

\n

(...)

\n

例子

\n

将以下行添加到 /etc/pam.d/login 以在登录时设置用户特定的 umask:

\n
    session optional pam_umask.so umask=0022\n
Run Code Online (Sandbox Code Playgroud)\n
\n

Ubuntu 18.04、Ubuntu 20.04

\n

在文件中/etc/login.defs,有一个条目UMASK 022可以替换为(在我的例子中)UMASK 027。然后重新启动。这产生:

\n

乌班图18.04:

\n
$ umask\n0022\n$ more /etc/login.defs | grep ^UMASK\nUMASK       027\n\n$ echo foo > terminal\n\nNOTE:  Open gedit from Dock and write file `dock`\n       Open gedit from Menu and write file `menu`\n\n$ ls -l dock menu terminal\n-rw-r--r-- 1 daniel daniel 4 nov  4 16:11 dock\n-rw-rw---- 1 daniel daniel 4 nov  4 16:11 menu\n-rw-r--r-- 1 daniel daniel 4 nov  4 16:11 terminal\n
Run Code Online (Sandbox Code Playgroud)\n

乌班图20.04:

\n
$ umask\n0007\n$ more /etc/login.defs | grep ^UMASK\nUMASK       027\n\n$ ls -l foo bar\nls: cannot access \'foo\': No such file or directory\nls: cannot access \'bar\': No such file or directory\n\n$ touch foo\n$ echo hello > bar\n$ ls -l foo bar\n-rw-rw---- 1 daniel daniel 6 nov  4 17:20 bar\n-rw-rw---- 1 daniel daniel 0 nov  4 17:20 foo\n
Run Code Online (Sandbox Code Playgroud)\n

可能会在 17.04 运行

\n

请注意,我的 Ubuntu 版本上不存在此文件,在这种情况下我们可以创建它。

\n
$ sudo sh -c "echo \'session optional pam_umask.so umask=0027\' >> /etc/default/login"\n\n$ more /etc/default/login\nsession optional pam_umask.so umask=0027\n
Run Code Online (Sandbox Code Playgroud)\n

邪恶的虫子

\n

现在,如果我们重新启动并在终端中询问 umask,我们仍然会得到0022(在 Ubuntu 18.04 的情况下),而不是0027设置的值。请参阅错误#1685754

\n

但是,如果我们打开一个应用程序(例如文本编辑器)并保存文件,我们会注意到新的 umask 影响的权限。umask从菜单打开它,而不是从终端打开,因为它似乎从终端中获取(坏) 。

\n

参考

\n\n


Zia*_*zis 1

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
Run Code Online (Sandbox Code Playgroud)

这就是你~/.profile所说的字面意思。更改后是否重新登录?它应该工作正常。

还:

This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.
Run Code Online (Sandbox Code Playgroud)

实际上在新安装的 ubuntu 17.04 上证实了这个问题。即使完全更新仍然会导致此问题出现,甚至~/.bash_profile被忽略,命令解释器似乎在登录后不读取这些文件的问题。

~/.bashrc您现在可以使用,它仍然可以正常工作并在登录期间读取。

因此,在深入研究之后,bash 似乎不再默认使用 --login 运行,这意味着它不会读取 ~/.profile。使用 ~/.profile 中的 umask 启动新的 bash,并bash --login正确设置 umask 启动没有它的 bash,但会忽略 ~/.profile。不确定改变了什么,但这对我来说似乎是一个错误,除非是故意改变的。


mur*_*uru 0

如果您使用 GDM,它的读取方式~/.profile与 LightDM 不同。并且终端通常会打开一个非登录 shell。最终效果是,~/.profile当您使用 GDM 登录后打开终端时,根本不会加载。

任何一个:

  • 将您的设置放入~/.bashrc, 或
  • 将您的终端设置为启动登录 shell,或者
  • 切换到 LightDM