Linux Add User to Group

 

Linux Add User to Group using usermod Command.

 

   The step by step command example below show how to use Linux usermod command in Linux to add user to group that already available on your Linux system.  This usermod command is use to add existing user to existing group in Linux system.  You may need to check existing Linux user and check existing Linux group available on your Linux system... and then we use usermod command to add user to group.  Please note you may need to login as root user to execute command as show on step by step command example below.

 

Check Linux user group.

 

The id command below show the group id the user belong to and the primary group of that user.  Please note that we use linuxuser as user on command example on below procedure.

Check Linux user group id

[root@fedora ~]# id linuxuser

uid=505(linuxuser) gid=505(linuxuser) groups=505(linuxuser)

[root@fedora ~]#

 

then we also use the id command to check root user group,  this procedure is only to show the root group id that we want to add user to root group on next command example below...

Check Linux root user group id

[root@fedora ~]# id root

uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

[root@fedora ~]#

 

Add user to group root

 

  On this command example, we use usermod command to add user to group root user belong to using usermod command.

Add user to group root

[root@fedora ~]# usermod -a -G root,bin,daemon,sys,adm,disk,wheel linuxuser

[root@fedora ~]#

 

verify that you already add user to group that user belong to using id command.

verify user group id change

[root@fedora ~]# id linuxuser

uid=505(linuxuser) gid=505(linuxuser) groups=505(linuxuser),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

[root@fedora ~]#

.

Change primary user group

 

  To change user primary group execute usermod command below.

change root group

[root@fedora ~]# usermod -g root -o linuxuser

[root@fedora ~]#

 

Verify user primary group change to root user primary group... watch how this command change user group to the root group (no more gid=505(linuxuser)).

Verify user primary group change

[root@fedora ~]# id linuxuser

uid=505(linuxuser) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

[root@fedora ~]#

 

The command example above just an example on how you can use the usermod command to change Linux user group... and this command test on Linux Fedora system and this may vary on other Linux systeem...

 

Keywords: linux add user to group, add user to group, linux add user to group root, add user to group root, add user to group, change user group, change primary user group