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: usermod -G without -a wipes a user's other group permissions

Permissions
~/tips/tip-permissions-usermod-ag-append

sudo usermod -G users alice

Shows why adding a group always needs the append flag.

This is one of those mistakes you only make once. usermod -G on its own doesn’t add a group. It replaces the whole list of extra groups.

See what happens with a test user:

sudo usermod -aG sudo alice
id alice
sudo usermod -G users alice
id alice

After the first command alice is in sudo. After the second she is in users and nothing else. Her sudo rights are gone, and so are any other groups she had, like docker or www-data. On your own account over SSH that can mean losing sudo on a remote server.

The -a flag means append, and it only works together with -G. I’d write them as -aG so they stay together:

sudo usermod -aG docker,media alice

Several groups go in one comma list without spaces.

If it already happened, there is no undo command. Look up the old memberships in a backup of /etc/group; Debian and Ubuntu keep a copy of the previous version as /etc/group-. Compare the two and add the groups back with -aG. If you removed your own sudo access, you’ll need another admin account, a root login or a console to repair it. Before you run usermod on your own account, keep a second root session open.

Further reading: usermod(8) manual page

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