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: HOME_MODE and DIR_MODE decide the permissions of new home folders

Permissions
~/tips/tip-permissions-home-mode-new-users

grep -E '^(HOME_MODE|UMASK)' /etc/login.defs

Sets how private the home folder of every new user account is.

Make a new user on a server and look at /home. Whether other accounts can peek into that new home folder depends on a setting most people never open, and on which command you used to create the user.

There are two tools and two config files. useradd reads /etc/login.defs, Debian and Ubuntu’s friendlier adduser reads /etc/adduser.conf:

grep -E '^(HOME_MODE|UMASK)' /etc/login.defs
grep -E '^(DIR_MODE|SYS_DIR_MODE)' /etc/adduser.conf
ls -ld /home/*

The login.defs man page says HOME_MODE is the mode for new home directories, and that useradd falls back to UMASK when it isn’t set. In adduser.conf the setting is DIR_MODE; the Ubuntu 24.04 man page gives 0700 as its default and SYS_DIR_MODE 0755 for system users. Whatever your files say wins, so check them instead of trusting a blog post (this one included).

To make new homes private for the group as well as for others, I’d set:

# /etc/login.defs
HOME_MODE 0750

# /etc/adduser.conf
DIR_MODE=0750

On a machine where I’m the only person this hardly matters. On a server shared with a few friends, it’s the difference between everyone reading each other’s dotfiles or not.

The caveat: this only touches home folders created from now on. Existing ones keep their mode, so fix those yourself with sudo chmod 750 /home/alice. And don’t lock it down without thinking: the adduser.conf man page warns that things like ~user web pages or mail delivered into the home folder need a looser mode.

Further reading: login.defs manual page, adduser.conf manual page (Ubuntu)

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