How to add user to a Group in Linux

Add user to a Group

usermod - modify user account

A user does not belong to a specific group could cause application problem.

To check a user's existing group:
$ id user_name
To add an existing user to a group:
# usermod -aG group-name user-name

For example, to add user ec2-user to docker group:

$ sudo usermod -aG docker ec2-user

You need to logout and login to see the effect.

Be careful not to use

# usermod -g group-name user-name

It will change the user's primary group, instead of just adding to the group.

See also: How to remove user from a group in linux

Featured Post

When you copy an AWS EC2 snapshot, you can choose to encrypt the copy

Encrypted Snapshots When you copy a snapshot, you can choose to encrypt the copy (if the original snapshot was not encrypted) or you can s...