在Red Hat Enterprise Linux 或其他類似的Linux發(fā)行版中,全局umask設(shè)置通常在幾個不同的系統(tǒng)級配置文件中定義。以下是一些可能設(shè)置umask的地方:
(1)/etc/profile:
這是為系統(tǒng)上的所有用戶設(shè)置全局環(huán)境變量和啟動程序的地方。通常,umask設(shè)置會在這個文件中定義。
[root@iZ8vb0njm9zbv3qvisb1ktZ ~]# vim /etc/profile
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
fi
USER="`/usr/bin/id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export 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`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
if [ -n "${BASH_VERSION-}" ] ; then
if [ -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/bashrc
fi
fi
(2)/etc/bashrc 或 /etc/bash.bashrc:
對于使用Bash shell的系統(tǒng),這個文件包含了所有Bash用戶的全局定義和別名。umask也可能在這里設(shè)置。
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /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.
# Prevent doublesourcing
if [ -z "$BASHRCSOURCED" ]; then
BASHRCSOURCED="Y"
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -z "$PROMPT_COMMAND" ]; then
case $TERM in
xterm*|vte*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
PROMPT_COMMAND="__vte_prompt_command"
else
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
fi
;;
screen*)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
fi
# Turn on parallel history
shopt -s histappend
history -a
# Turn on checkwinsize
shopt -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/ directory
fi
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it gets undefined at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
# 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 file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
SHELL=/bin/bash
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
fi
fi
# vim:ts=4:sw=4
(3)Shell個人配置文件:
如~/.bashrc, ~/.bash_profile, ~/.profile等,這些是針對單個用戶的配置文件。雖然這些不是全局設(shè)置,但是管理員可能已經(jīng)為每個用戶配置了默認的umask。
PAM (Pluggable Authentication Modules) 配置:
在/etc/pam.d/目錄下的PAM配置文件中,可能會有pam_umask.so模塊的相關(guān)配置。例如,在/etc/pam.d/login文件中,可能會有如下行來設(shè)置umask:
session optional pam_umask.so
或者指定了一個默認的umask值:
session optional pam_umask.so umask=0022
(4)Systemd服務(wù)文件:
如果你是在Systemd服務(wù)中更改umask,那么你需要查看服務(wù)的配置文件。這些文件通常位于/etc/systemd/system/或/usr/lib/systemd/system/目錄下。在服務(wù)文件中,可以通過UMask=指令設(shè)置umask。
要查看當前的全局umask設(shè)置,你可以在終端中運行以下命令:
umask
這將顯示當前shell會話的umask值。要找出是哪個配置文件設(shè)置了這個值,你可能需要手動檢查上述文件。你可以使用grep命令來幫助搜索這些文件中的umask設(shè)置:
[root@iZ8vb0njm9zbv3qvisb1ktZ 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:UMask=0066
請注意,如果你的系統(tǒng)配置了多個地方設(shè)置了umask,最終的umask值將取決于這些配置的加載順序和優(yōu)先級。通常,最后執(zhí)行的配置文件中的設(shè)置將覆蓋之前的設(shè)置。
那么,文件掩碼到底是什么呢?
其實在Linux系統(tǒng)中,文件掩碼(umask)用于確定新創(chuàng)建的文件或目錄的默認權(quán)限。umask值是一個三位的八進制數(shù),每一位分別對應用戶(u)、組(g)和其他(o)的權(quán)限。
umask值實際上是一個“反向”的權(quán)限設(shè)置。也就是說,它定義了哪些權(quán)限應該被移除,而不是哪些權(quán)限應該被賦予。因此,要得到新創(chuàng)建的文件或目錄的默認權(quán)限,你需要從全權(quán)限(即777對于目錄,666對于文件)中減去umask值。
如果umask值是022,那么:
對于目錄,全權(quán)限是777,減去umask值022后,得到的默認權(quán)限是755。也就是說,用戶有讀(r)、寫(w)和執(zhí)行(x)權(quán)限,組和其他用戶有讀和執(zhí)行權(quán)限。
對于文件,全權(quán)限是666,減去umask值022后,得到的默認權(quán)限是644。也就是說,用戶有讀和寫權(quán)限,組和其他用戶只有讀權(quán)限。文章來源:http://www.zghlxwxcb.cn/news/detail-792642.html
請注意,這只是默認權(quán)限。你可以在創(chuàng)建文件或目錄后,使用chmod命令來更改它們的權(quán)限。文章來源地址http://www.zghlxwxcb.cn/news/detail-792642.html
到了這里,關(guān)于Linux筆記:Linux中的文件系統(tǒng)權(quán)限的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!