What does usermod -aG do?

QuestionsQuestions8 SkillsProDec, 20 2025
0152

In Linux, the usermod -aG command is used to add a user to supplementary (secondary) groups. Here is a breakdown of what each part does:

  • -G (Groups): This flag tells the system you want to specify a list of supplementary groups. Crucially, if you use -G by itself, it will overwrite the user's current group memberships with only the ones you list.
  • -a (Append): This flag is used only with the -G option. It tells the system to add the new groups to the user's current list of groups, rather than replacing the existing ones.

Example in your Lab:

When you ran:

sudo usermod -aG developers userA
  • Before: userA was only in the userA group.
  • After: userA remained in the userA group AND was added to the developers group.

Why the -a is so important:

Imagine a user named "Alice" is already in the finance and hr groups.

  1. If you run sudo usermod -G IT Alice, she will be removed from finance and hr and put only in IT. This can break her access to files!
  2. If you run sudo usermod -aG IT Alice, she will stay in finance and hr and gain access to IT.

Summary: Always remember to use the -a (append) flag when adding a user to a new group unless you specifically want to remove them from all their other supplementary groups

0 Comments

no data
Be the first to share your comment!