Umask

如何在 Linux 下檢查所有使用者的 umask?

  • July 15, 2013

在 AIX 下,我可以檢查umask所有使用者:

cut -d : -f 1 /etc/passwd | while read ONELINE; do lsuser -a umask "$ONELINE"; done

但是如何檢查umaskLinux 下所有使用者的設置呢?(su對每個使用者然後umask命令?有沒有更好的方法呢?)

更新1:

這對所有使用者來說並不是最好的su,因為在一些 RHEL 伺服器上,一些使用者的預設 shell 是暫停/關閉..:

shutdown:x:6:0:shutdown;asdf;asdf;F:/sbin:/sbin/shutdown

所以如果我su對使用者…然後伺服器關閉?

**UPDATE2:**我為非基於 su 的答案創建了賞金。

您可以檢查使用:

for user in $(awk -F: '{print $1}' /etc/passwd); 
do 
   printf "%-10s" "$user" ; su -c 'umask' -l $user 2>/dev/null
done

為避免檢查系統使用者,請執行以下操作:

for user in $(awk -F: '( $3 >= 500 ){print $1}' /etc/passwd); 
do 
   printf "%-10s" "$user" ; su -c 'umask' -l $user 2>/dev/null
done

輸出:

ram       0022
shyam     0022
suraj     0022
vinayak   0022
javed     0022

umask通常通過配置文件設置系統範圍/etc/login.defs

$ grep UMASK /etc/login.defs 
UMASK           077

這個值可以被覆蓋,但通常不是通過/etc/bashrc/etc/profile和/或由他們的使用者$HOME/.bashrc(假設他們使用 Bash)。

如果您grep在上述文件中使用“umask”,您還會在 RHEL 框中註意到這一點:

$ grep umask /etc/bashrc /etc/profile
/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
/etc/profile:# By default, we want umask to get set. This sets it for login shell
/etc/profile:    umask 002
/etc/profile:    umask 022

深層發掘:

  • /etc/bashrc
# 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 ] && [ "`id -gn`" = "`id -un`" ]; then
  umask 002
else
  umask 022
fi
  • /etc/profile
# 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 ] && [ "`id -gn`" = "`id -un`" ]; then
   umask 002
else
   umask 022
fi

因此,至少在 RHEL 系統上,umask如果002您的 UID 大於 199,則為,022否則(系統帳戶)。

引用自:https://unix.stackexchange.com/questions/82638