brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: umask decides the permissions of every new file

Permissions
~/tips/tip-linux-umask

umask 027

Sets the default permissions for new files and directories so others get no access.

Why does a new file come out as 644 and a new directory as 755? The umask decides, and you can change it.

Run umask to see yours. A common value is 0022. Its bits are cleared from the default modes: 666 for files and 777 for directories. So 022 gives 644 and 755. Try a stricter one in your current shell:

umask 027
touch a.txt
mkdir d
ls -ld a.txt d

Now the file is 640 and the directory 750: group can read, others get nothing. That suits a shared server where I do not want other users reading my files by default.

The caveats: the umask only applies to the current shell and its children, so put it in ~/.profile or ~/.bashrc to keep it. It does not change files that already exist. And new files never get execute from the umask, since 666 has no x to begin with.

It looks like trivia until you share a machine. The default is fine for a personal laptop, but on a server with several accounts I would tighten it.

Further reading: umask man page (POSIX), Bash manual: Bourne Shell Builtins, On this site: stat -c prints the permissions as numbers, On this site: deny Read(./.env) so Claude never opens your secrets

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media All Permissions tips (30) All topics

Link