Linux下如何查看所有用户的umask?

Linux下如何查看所有用户的umask?

在 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对用户...那么服务器就会关闭?

更新2:我为非基于 su 的答案创建了赏金。

答案1

通常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
    

umask因此,至少在 RHEL 系统上,002如果您的 UID 大于 199,则为022否则(系统帐户)。

答案2

您可以使用(以 root 身份执行)进行检查:

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

相关内容