20

Under AIX I can check the umask for all users with:

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

But how can I check the umask setting for all users under Linux? (su to every user and then umask command? Are there any better ways for it?)

UPDATE1:

It's not the best to su to all users, because on some RHEL servers the default shell for a few user is halt/shutdown..:

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

so if I su to the user... then the server shuts down?

UPDATE2: I created a bounty for a non-su based answer.

3
  • I have already mentioned for avoid system user ($3 > 500), means check above UID 500 Commented Jul 11, 2013 at 15:43
  • again: I need to check umask for all users, not excluding system users :) Commented Jul 11, 2013 at 17:02
  • we can check for valid shell, what you think ? , means if shell is other that /bin/bash , then we can skip that user. isn't it ? Commented Jul 12, 2013 at 13:41

2 Answers 2

15

The umask is typically set system wide through the config file: /etc/login.defs:

$ grep UMASK /etc/login.defs 
UMASK           077

This value can be overridden but typically is not through either /etc/bashrc, /etc/profile and/or by the users in their $HOME/.bashrc (Assuming they're using Bash).

If you grep for "umask" in those aforementioned files you'll also notice this on RHEL boxes:

$ 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

Digging deeper:

  • /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
    

So at least on RHEL system's the umask is either 002 if your UID is greater than 199, and 022 otherwise (system accounts).

1
  • For Ubuntu and (probably) Debian-based systems, you should do this in ~/.profile, which has the default value commented at the top of the file for you to uncomment and modify on a per-user basis.
    – code_dredd
    Commented Jun 5, 2018 at 19:24
11

You can check using (execute as root) :

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

To avoid checking system user do :

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

OutPut:

ram       0022
shyam     0022
suraj     0022
vinayak   0022
javed     0022
7
  • 1
    ok, thanks, but are there any ways to check the umask without "su"ing to the user? Commented Jul 11, 2013 at 14:38
  • if you have manually set , say in ~.bashrc then you can grep into this file. Commented Jul 11, 2013 at 14:49
  • It could be set in many places... that's why grepping is not the best solution Commented Jul 11, 2013 at 14:51
  • then we have to check in many place Commented Jul 11, 2013 at 14:52
  • it should be better , if you have set umask in per user in common file eg .bashrc Commented Jul 11, 2013 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .