Ubuntu Server Tutorial–How to add users to group

ubuntu-logoIn the next few posts we will discuss about Ubuntu Server Tutorial for beginner. We try to include some basic tutorial to handle Ubuntu Server via command line. On this first Ubuntu Server tutorial, we will show you how to add new users to existing group, create new group and add existing users to existing group. This practice will be useful when we are managing multiple users on Ubuntu or Linux networking using Samba server. 

A. Add new group in Ubuntu Server

To add new Group, we can use “groupadd” command. See this example below to add new group called “gis”.

groupadd gis

Every group exist in Ubuntu is saved in /etc/group. Now check if “gis” group is listed on /etc/group.

grep gis /etc/group

It will produce something like this:

gis:x:1001:

B. Add new user to to existing Group

To create a new user (tom) and add the new user to existing group (i.e: gis) use this command:

useradd –G gis tom

Now execute grep command again.

grep gis /etc/group

you should see something like this

gis:x:1001:tom

If more than 1 users are listed as gis group, it shows like this

gis:x:1001:tom,jerry

C. Add existing user to existing group

To add a user that already exist on the system to a specific group, we can use usermod command.

usermod –a –G gis dhani

The command above will add dhani to group secondary group gis.  To change the primary group of a user, use –g option instead of –a –G

usermod –g www dhani

the command will change dhani’s primary group to www