What command would you use to add a user to a group in Linux?

Disable ads (and more) with a premium pass for a one time $4.99 payment

Boost your Linux skills with the CompTIA Linux+ Certification Exam simulator. Engage with multiple choice questions and detailed feedback. Master Linux concepts and prepare for your exam with confidence!

The command to add a user to a group in Linux is indeed "usermod -aG". This command utilizes the usermod utility, which is specifically designed for modifying user accounts. The options provided here have specific meanings:

  • The "-a" option stands for "append," and is crucial when adding a user to an additional group without removing them from any groups they are already a part of. Without this option, the user would be removed from all other groups to which they belong, which is typically not the desired outcome.

  • The "G" option specifies the group or groups that the user is being added to. You can list multiple groups by separating them with commas, for instance, "usermod -aG group1,group2 username".

In contrast, the other commands listed do not serve the purpose of adding a user to a group in the way that is intended. The "-g" option is used to set a user's primary group, which would change the user's main group rather than simply adding them to another. The "-r" option is meant for modifying system accounts and is not applicable for adding users to groups. The "-d" option is used for changing a user's home directory, which does not relate to group

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy