Linux-for-Sys-Ads/C2/Assigning-groups-on-user-creation/English-timed

From Script | Spoken-Tutorial
Revision as of 17:16, 6 September 2022 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
00:01 Hello and welcome to the spoken tutorial on Assigning Groups on User Creation in Linux.
00:08 In this tutorial we will learn about

Creating a user group /etc/group file

00:17 Assigning groups to users at the time of account creation
00:22 We will do this through some examples.
00:25 To record this tutorial, I am using Ubuntu Linux 16.04 Operating System
00:32 To practice this tutorial,

you should have gone through Linux System Administration tutorials on this website.

00:40 you must have root access to your computer.
00:44 What is a group in Linux?
00:47 We can understand group as a collection of users.
00:51 In a college system, a group can be different departments like CSE, Electrical etc.
00:58 Groups can also be different clubs like music club, sports club, literature club, etc.
01:06 Linux supports two types of groups.

Primary group and Supplementary group

01:12 Every user must belong to one and only one primary group.
01:17 This is the default group for the user when the user logs in.
01:22 For example: a student must belong to one and only one department.
01:28 A user can be a member of more than one group.
01:32 Those groups are called supplementary groups.
01:36 These groups are assigned to the user, to provide him additional access to resources.
01:43 More on access mechanism or permission will be discussed in subsequent tutorials.
01:50 Let’s take an example. User radha belongs to the CSE department.
01:56 She is also a member of the music club and sports club.
02:01 In this scenario, CSE is the primary group for radha.
02:05 And she is a member of two supplementary groups - music club and sports club.
02:12 Let’s create this scenario in our system.
02:16 First, we will create group CSE.
02:19 And we will use addgroup command in order to create this group.
02:24 Open the Terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard.
02:32 Now, we should login as superuser or root user.
02:37 To do so type: sudo space su and press Enter.
02:44 Type the admin password and then press Enter.
02:48 Notice, our login prompt has changed to a hash symbol.
02:53 This indicates that we are in the root user mode.
02:57 Here onwards, please remember to press the Enter key after typing each command.
03:03 Now type addgroup space cse
03:08 This will create group cse.
03:12 Linux automatically allocates a Unique ID for each group that is created.
03:18 Here, GID, that is Group ID is 1002.
03:22 Alternatively, we can mention a GID of our choice.
03:28 For this, we need to use hyphen gid option along with the addgroup command.
03:35 GIDs in the range of 0 to 999 are reserved for the system users.
03:42 So, always choose a number greater than or equal to 1000 as GID
03:49 Let’s us create a group Music_club with the GID 1012.
03:55 On the terminal type:

addgroup space hyphen gid 1012 space Music underscore club

04:06 Here type M is in capital letter.
04:10 Notice, it is showing some error.
04:13 Actually, we should have written m in lowercase letter.

Let’s try that.

04:19 Press the Up arrow key to get the previously executed command.
04:24 Change capital M to m in lowercase letter.
04:30 The command is working now.
04:32 So, always remember to use lowercase letters while writing group names.
04:38 Similarly let’s create another group sports underscore club.
04:43 This time no need to mention the GID.
04:48 Now we have three groups cse, music underscore club and sports underscore club.
04:55 How can we check the details of the created group?

Type cat space /etc/group

05:05 There will be an entry in this file for every user on the system.
05:11 Each line has four fields separated by a colon symbol.
05:16 The first field is the name of the group.
05:19 The second field is the encrypted password for the group.
05:24 Third field shows the GID as a number.
05:28 Fourth field contains the list of users that belong to that group separated by commas.
05:35 This list contains all users who have this group as a secondary group.
05:41 We can see the entries for cse, music underscore club and sports underscore club groups.
05:49 Notice, music underscore club has Gid 1012 which we mentioned during group creation.
05:57 Here, the fourth field is empty for all the groups.
06:02 This is because there are no members in these groups, as of now.
06:07 The password field is x.
06:10 We will discuss about the password field and list of members field in detail, in a separate tutorial on groups.
06:18 Now, how can we specify the primary and supplementary groups while creating the user?

Let us see an example.

06:26 To specify that user radha belongs to the primary group cse, type:

adduser space hyphen ingroup space cse space radha

06:40 Type the password as pass underscore radha and press Enter.
06:46 Retype the same password and press Enter.
06:50 Type name as Radha with capital R.

And proceed as we have done before.

06:59 We have successfully created user radha with primary group cse.
07:05 So, you should use ingroup option to specify primary group’s name while creating the user.
07:13 As we know, radha is a member of music underscore club.
07:17 So music underscore club will be the supplementary group for the user radha.
07:23 Type adduser space radha space music underscore club
07:31 Remember.

To add supplementary groups using adduser command, you should have an existing user.

07:38 Here, we have first created the user radha. Then added radha to the supplementary group using adduser command.
07:46 If you need to specify that radha is also a member of sports club type:

adduser space radha space sports underscore club

07:59 Let’s check user radha’s details using id command.
08:04 Type id space radha
08:08 Notice, User radha is in group cse which has GID 1002
08:15 That is the primary group for radha.
08:19 Next, there is the list of groups, where user radha is member of.
08:25 Along with primary group cse, radha is also a member of two supplementary groups music underscore club and sports underscore club.
08:35 Now let’s check our /etc/group file for the entry of radha
08:42 Type: grep space radha space /etc/group
08:49 Notice, you can see user radha is the member of groups music underscore club and sports underscore club
08:58 But not as a member of the primary group that is cse.
09:03 So the group file will list only the supplementary groups in which the user is associated.
09:10 Check the /etc/passwd file for the details of the username radha.
09:17 Type grep space radha space /etc/passwd
09:25 Notice, the fourth field is 1002
09:29 It is the GID for the group cse.
09:33 It is the primary group for radha.
09:36 So, remember /etc/passwd shows primary group ID for a user
09:43 /etc/group file shows list of usernames who have the group as a supplementary group
09:51 Command id space username shows the details of both primary and supplementary groups
09:59 You can also specify the group id instead of group’s name while creating the user.
10:05 Let us create a user suraj and assign him to the group cse using the gid.
10:12 We know group cse has GID 1002
10:17 So type: adduser space hyphen gid space 1002 space suraj
10:26 You should use hyphen gid option to specify the group ID.
10:32 Use pass underscore suraj as the password
10:37 Retype the password

Full Name as Suraj with S in capital letter.

10:45 Proceed as we have done for the previous users.
10:49 We have successfully created user suraj with primary group cse.
10:55 To exit from the root user access, type exit
11:00 This brings us to the end of this tutorial.

Let us summarize.

11:05 In this tutorial we learnt about-

Creating primary group

11:10 Assigning user to the primary group
11:13 Assigning user to the supplementary group /etc/group file
11:19 Assigning groups to users at the time of account creation
11:24 As an assignment- Create two groups: cultural , literature
11:30 Now create a user ajay with Home directory as /home/ajay underscore dir
11:39 User id as 1090
11:42 Primary group as cultural
11:45 Supplementary group as literature
11:49 Add comments "Native: Mumbai"
11:52 Use the command id to check the user details
11:56 Check the details of user ajay in /etc/passwd and /etc/group files
12:05 The video at the following link summarises the Spoken Tutorial project.

Please download and watch it.

12:13 The Spoken Tutorial Project team conducts workshops and gives certificates.

For more details, please write to us.

12:23 Please post your timed queries in this forum.
12:27 Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
12:33 The script has been contributed by Antara and this is Praveen from IIT Bombay signing off.

Thank you for joining.

Contributors and Content Editors

PoojaMoolya