A shell’s umask doesn’t reach a service started by systemd. Those get 0022 by default, so every file they create is readable by all users. One line in the unit changes that.
Add a drop-in for the service:
sudo systemctl edit myapp.service
[Service]
UMask=0027
After sudo systemctl restart myapp, new files come out as 640 and new folders as 750. The owner can read and write, the group can read, and other users get nothing. For a service that writes logs, exports or uploaded files, that’s usually what you want.
Check what a service runs with now:
systemctl show -p UMask myapp.service
I like 0027 for apps that share files with a web server through a group, and 0077 for anything that only the service itself should read.
The umask only removes bits, it never adds them. If the program creates a file with mode 600 itself, a looser umask won’t open it up. And existing files keep their permissions; fix those once with chmod. Some programs set their own umask at start, which overrides this, so if nothing changes, look in the app’s own settings.
Further reading: systemd.exec(5): UMask=