企业建站多站点管理系统,灌南县规划局网站理想家园规划建设,蓝色网站导航,欧洲网站后缀在Red Hat Enterprise Linux 或其他类似的Linux发行版中#xff0c;全局umask设置通常在几个不同的系统级配置文件中定义。以下是一些可能设置umask的地方#xff1a;
#xff08;1#xff09;/etc/profile:
这是为系统上的所有用户设置全局环境变量和启动程序的地方。通…在Red Hat Enterprise Linux 或其他类似的Linux发行版中全局umask设置通常在几个不同的系统级配置文件中定义。以下是一些可能设置umask的地方
1/etc/profile:
这是为系统上的所有用户设置全局环境变量和启动程序的地方。通常umask设置会在这个文件中定义。
[rootiZ8vb0njm9zbv3qvisb1ktZ ~]# vim /etc/profileEUID/usr/bin/id -uUID/usr/bin/id -rufiUSER/usr/bin/id -unLOGNAME$USERMAIL/var/spool/mail/$USER
fi# Path manipulation
if [ $EUID 0 ]; thenpathmunge /usr/sbinpathmunge /usr/local/sbin
elsepathmunge /usr/local/sbin afterpathmunge /usr/sbin after
fiHOSTNAME/usr/bin/hostname 2/dev/null
HISTSIZE1000
if [ $HISTCONTROL ignorespace ] ; thenexport HISTCONTROLignoreboth
elseexport HISTCONTROLignoredups
fiexport PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] [ /usr/bin/id -gn /usr/bin/id -un ]; thenumask 002
elseumask 022
fifor i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; doif [ -r $i ]; thenif [ ${-#*i} ! $- ]; then. $ielse. $i /dev/nullfifi
doneunset i
unset -f pathmungeif [ -n ${BASH_VERSION-} ] ; thenif [ -f /etc/bashrc ] ; then# Bash login shells run only /etc/profile# Bash non-login shells run only /etc/bashrc# Check for double sourcing is done in /etc/bashrc.. /etc/bashrcfi
fi
2/etc/bashrc 或 /etc/bash.bashrc:
对于使用Bash shell的系统这个文件包含了所有Bash用户的全局定义和别名。umask也可能在这里设置。
# /etc/bashrc# System wide functions and aliases
# Environment stuff goes in /etc/profile# Its NOT a good idea to change this file unless you know what you
# are doing. Its 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.# Prevent doublesourcing
if [ -z $BASHRCSOURCED ]; thenBASHRCSOURCEDY# are we an interactive shell?if [ $PS1 ]; thenif [ -z $PROMPT_COMMAND ]; thencase $TERM inxterm*|vte*)if [ -e /etc/sysconfig/bash-prompt-xterm ]; thenPROMPT_COMMAND/etc/sysconfig/bash-prompt-xtermelif [ ${VTE_VERSION:-0} -ge 3405 ]; thenPROMPT_COMMAND__vte_prompt_commandelsePROMPT_COMMANDprintf \033]0;%s%s:%s\007 ${USER} ${HOSTNAME%%.*} ${PWD/#$HOME/\~}fi;;screen*)if [ -e /etc/sysconfig/bash-prompt-screen ]; thenPROMPT_COMMAND/etc/sysconfig/bash-prompt-screenelsePROMPT_COMMANDprintf \033k%s%s:%s\033\\ ${USER} ${HOSTNAME%%.*} ${PWD/#$HOME/\~}fi;;*)[ -e /etc/sysconfig/bash-prompt-default ] PROMPT_COMMAND/etc/sysconfig/bash-prompt-default;;esacfi# Turn on parallel historyshopt -s histappendhistory -a# Turn on checkwinsizeshopt -s checkwinsize[ $PS1 \\s-\\v\\\$ ] PS1[\u\h \W]\\$ # You might want to have e.g. tty in prompt (e.g. more virtual machines)# and console windows# If you want to do so, just add e.g.# if [ $PS1 ]; then# PS1[\u\h:\l \W]\\$ # fi# to your custom modification shell script in /etc/profile.d/ directoryfiif ! shopt -q login_shell ; then # Were not a login shell# Need to redefine pathmunge, it gets undefined at the end of /etc/profilepathmunge () {case :${PATH}: in*:$1:*);;*)if [ $2 after ] ; thenPATH$PATH:$1elsePATH$1:$PATHfiesac}# By default, we want umask to get set. This sets it for non-login shell.# Current threshold for system reserved uid/gids is 200# You could check uidgid reservation validity in# /usr/share/doc/setup-*/uidgid fileif [ $UID -gt 199 ] [ /usr/bin/id -gn /usr/bin/id -un ]; thenumask 002elseumask 022fiSHELL/bin/bash# Only display echos from profile.d scripts if we are no login shell# and interactive - otherwise just process them to set envvarsfor i in /etc/profile.d/*.sh; doif [ -r $i ]; thenif [ $PS1 ]; then. $ielse. $i /dev/nullfifidoneunset iunset -f pathmungefifi
# vim:ts4:sw4
3Shell个人配置文件:
如~/.bashrc, ~/.bash_profile, ~/.profile等这些是针对单个用户的配置文件。虽然这些不是全局设置但是管理员可能已经为每个用户配置了默认的umask。
PAM (Pluggable Authentication Modules) 配置: 在/etc/pam.d/目录下的PAM配置文件中可能会有pam_umask.so模块的相关配置。例如在/etc/pam.d/login文件中可能会有如下行来设置umask
session optional pam_umask.so或者指定了一个默认的umask值
session optional pam_umask.so umask00224Systemd服务文件:
如果你是在Systemd服务中更改umask那么你需要查看服务的配置文件。这些文件通常位于/etc/systemd/system/或/usr/lib/systemd/system/目录下。在服务文件中可以通过UMask指令设置umask。
要查看当前的全局umask设置你可以在终端中运行以下命令
umask这将显示当前shell会话的umask值。要找出是哪个配置文件设置了这个值你可能需要手动检查上述文件。你可以使用grep命令来帮助搜索这些文件中的umask设置
[rootiZ8vb0njm9zbv3qvisb1ktZ system]# grep -ir umask /etc/profile /etc/bashrc /etc/bash.bashrc /etc/pam.d/ /etc/systemd/system/ /usr/lib/systemd/system/
/etc/profile:# By default, we want umask to get set. This sets it for login shell
/etc/profile: umask 002
/etc/profile: umask 027
/etc/bashrc: # By default, we want umask to get set. This sets it for non-login shell.
/etc/bashrc: umask 002
/etc/bashrc: umask 022
grep: /etc/bash.bashrc: No such file or directory
/usr/lib/systemd/system/rsyslog.service:UMask0066
请注意如果你的系统配置了多个地方设置了umask最终的umask值将取决于这些配置的加载顺序和优先级。通常最后执行的配置文件中的设置将覆盖之前的设置。
那么文件掩码到底是什么呢
其实在Linux系统中文件掩码umask用于确定新创建的文件或目录的默认权限。umask值是一个三位的八进制数每一位分别对应用户u、组g和其他o的权限。
umask值实际上是一个“反向”的权限设置。也就是说它定义了哪些权限应该被移除而不是哪些权限应该被赋予。因此要得到新创建的文件或目录的默认权限你需要从全权限即777对于目录666对于文件中减去umask值。
如果umask值是022那么
对于目录全权限是777减去umask值022后得到的默认权限是755。也就是说用户有读r、写w和执行x权限组和其他用户有读和执行权限。
对于文件全权限是666减去umask值022后得到的默认权限是644。也就是说用户有读和写权限组和其他用户只有读权限。
请注意这只是默认权限。你可以在创建文件或目录后使用chmod命令来更改它们的权限。