I would like to find the umask value for a particular system user, the one that is applied when a script running as this user creates a new directory. I'm using both Ubuntu 16.04 and 20.04 systems.

The closest answer I can find to this is this question. I don't understand a word of it, but I tried the script

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

given in the accepted answer; it printed the word "root" and then froze the system.

How do I find the umask value for a given system user?

  • 1
    It probably didn't freeze the system - likely su wrote its Password: prompt to standard output (which you discarded) and is waiting for you to respond Commented May 23, 2021 at 21:26
  • Good note, probably. I don't know Bash, so unless someone can correct that for me, I still can't use it. Commented May 23, 2021 at 21:38
  • In order to work properly, the script above needs to be run as root. Otherwise su asks for a password and it will hang. However, that segues into a recommendation that you don't ever run shell scripts that you don't understand, especially as the root user.
    – Chris
    Commented May 23, 2021 at 21:39
  • I don't want to run a script I don't understand, but I have a problem to solve and Linux doesn't give me much choice. I simply don't have days or weeks available to decipher this kind of incomprehensible Bash gibberish, and I can't seem to rely on "free community support!" to provide explanations when they keep posting it. Commented May 23, 2021 at 21:47
  • Have you tried running the umask command as the appropriate user? See umask --help Commented May 31, 2021 at 16:36

1 Answer 1


To determine the umask of a user at a given time, you can just run the umask command as that user. The script you've given in the question fetches a list of users from the /etc/passwd file and then runs the umask command on each in succession. But it has some issues, not least of which is it will hang, waiting for a password, if run as a non-root user.

A user can change their umask at any time (actually, a user doesn't even have a umask, the umask is process-specific), so you shouldn't be depending on this to be the same every time. If you need to know what umask a user has when they're running a shell script, just add the umask command into that shell script. Or just ignore the umask entirely and chmod the directory to whatever mode you want it to be.

  • 1
    Thanks for the explanation! In this case, I'm looking for the umask value of a system user, so the user doesn't have a login and I can't run the umask command as that user. If I try $ sudo -u <username> umask, it returns sudo: umask: command not found. Commented May 23, 2021 at 21:51
  • @BoreaDeitz I strongly suspect you have some kind of XY problem here. You should never need to know the umask of any user- if you care about the permissions of a directory that user creates in a script, just modify the script to explicitly chmod the directory. The sudo: umask: command not found error might be a PATH thing- try entering the full path of umask. It's /usr/bin/umask on my system but you can check what it is on yours with which umask.
    – Chris
    Commented May 23, 2021 at 21:56
  • @BoreaDeitz But basically you'll probably get better results if you ask about the underlying problem you're trying to solve.
    – Chris
    Commented May 23, 2021 at 21:58
  • 2
    On Ubuntu AFAIK there's no standalone umask program, insteadumask` is a builtin in both bash and dash (which is sh) so it's a lack-of-shell issue rather than a path issue - try sudo -u <username> sh -c umask Commented May 23, 2021 at 22:04
  • 1
    @BoreaDeitz Please do keep in mind that that gives you the system default for umask for that user, but if you assume the umask is unchangeable you might get burnt later.
    – Chris
    Commented May 23, 2021 at 23:57

You must log in to answer this question.

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