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: gpasswd -d removes a user from one group and leaves the rest of their permissions alone

Permissions
~/tips/tip-permissions-gpasswd-remove-from-group

sudo gpasswd -d alice docker

Takes one user out of one group without touching other memberships.

Taking someone out of a group should be the easy part, but usermod has no clean option for it. gpasswd -d does exactly that one thing.

Name the user and the group:

sudo gpasswd -d alice docker
id alice
getent group docker

It prints Removing user alice from group docker, and id shows the other groups are still there. With usermod -G you’d have to type the full list of groups the user should keep, and one forgotten name removes more than you wanted.

It fits when someone moves to another role or when you clean up after a test. The docker group is a good one to check, since membership there is as good as root.

The command also adds people with -a, and lets you set the full member list with -M, but for adding I’d stick with usermod -aG.

The change only affects new logins. Any session the user has open keeps the group until they log out, and processes they started earlier keep it until they end. If the removal is about trust, like an employee leaving, end their sessions as well with loginctl terminate-user alice. Also check whether the group is the user’s primary group: gpasswd -d only removes the extra membership, and the primary group is changed with usermod -g.

Further reading: gpasswd(1) 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