usermod Command

Add a user to a group

Price range: €18.64 through €26.12

Command:

bash
sudo usermod -aG {group_name} {username}

Explanation:

  • sudo: Runs the command with superuser privileges, as modifying user groups typically requires root access.
  • usermod: A command used to modify a user’s account settings.
  • -aG: The -a option appends the user to the specified group(s), and the -G option specifies the group(s) to which the user will be added.
  • {group_name}: The name of the group you want to add the user to (e.g., sudodevelopers).
  • {username}: The username of the user you want to add to the group (e.g., johnalice).

Example:

To add the user john to the group sudo, the command would be:

bash
sudo usermod -aG sudo john

Result:

This command will add the user john to the sudo group, allowing them to execute commands with elevated privileges if required.


Additional Notes:

  • After adding a user to a group, the user will typically need to log out and back in for the group changes to take effect.
  • To verify that the user has been added to the group, you can use the groups command:
    bash
    groups {username}

    For example:

    bash
    groups john
Select options This product has multiple variants. The options may be chosen on the product page