Stop letting users squat on secondary groups
User & Group Management
Stop letting users squat on secondary groups
🧩 The Challenge
Dealing with a user who keeps popping up in groups they shouldn’t be in after an automated cleanup script runs is enough to drive anyone up the wall. You think you’ve scrubbed their access, but there they are, still lurking in the web-admin group.
💡 The Fix
Use the gpasswd command to surgically remove a user from a specific group rather than trying to overwrite the entire group membership file or playing games with usermod. It keeps your hands clean and leaves the rest of the user’s secondary groups exactly where they need to be.
gpasswd -d username groupname
⚙️ Why It Works
This utility talks directly to /etc/group and handles the locking properly, so you don’t end up with mangled files if two things try to update group membership at the exact same moment. It’s the most reliable way to yank someone out of a single group without side effects.
🚀 Pro-Tip: Always check groups username right after just to confirm the removal actually stuck.
Linux Tips & Tricks | © ngelinux.com | 9/26/2026
