We help IT Professionals succeed at work.

add user to group linux

Medium Priority
136 Views
Last Modified: 2019-11-10
hi how can i add user to a group in linux i what to move user from root group to another user
group
Comment
Watch Question

David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You can also do this with command...

# Associate $user with a new $group list
usermod -aG $group $user

Open in new window


This command overwrites the $group list for some $user, so old group(s) will be lost + new $group(s) will be associated.

Author

Commented:
am geting this
[root@mylinux usr1]# usermod -aG oracle calapp
[root@mylinux usr1]# ls -ltr
total 0
drwxr-xr-x. 2 root root 6 Nov  9 13:26 Oracle
[root@mylinux usr1]#
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Your example reflects directory listing.
Id username
Will output info about the user and which groups the user belongs to.
The primary group association is part of the user's entry in /etc/passwd
The supplemental additional are reflected in the /etc/group file where the username is appended to the group name.

David kindly provided an example how to add a secondary group to a user
The destination (manual pages for usermod)
-g sets the default, primary group membership I think it can only use one
-G sets additional and can have multiple/list of groups separated by comma.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
$ does not belong as it converts your input into variable's that are not defined

Use
usermod -aG oracle,calap

Author

Commented:
i use chown -R calapp:oracle Oracle
chown -R calapp:oracle Oracle
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
As you note, to change ownership of files, directories chown chgrp are the tools to use.
Your question dealt with changing user group membership with directory listing as an illustration.