Difference between revisions of "Linux-for-Sys-Ads/C2/Assigning-groups-on-user-creation/English"
Pravin1389 (Talk | contribs) (Created page with "'''Title of script: Assigning Groups on User Creation''' '''Author: Antara Roy Choudhury''' '''Keywords: group, primary group, supplementary group, assigning group, specify...") |
Nancyvarkey (Talk | contribs) |
||
Line 50: | Line 50: | ||
|- | |- | ||
|| Slide 7: | || Slide 7: | ||
− | || *Every '''user''' must belong to one and only one''' primary group'''. | + | || |
+ | *Every '''user''' must belong to one and only one''' primary group'''. | ||
*This is the default''' group''' for the '''user''' when the '''user '''logs in. | *This is the default''' group''' for the '''user''' when the '''user '''logs in. | ||
*For example: a student must belong to one and only one '''department'''. | *For example: a student must belong to one and only one '''department'''. | ||
Line 56: | Line 57: | ||
|- | |- | ||
|| Slide 8: | || Slide 8: | ||
− | || *A '''user''' can be a member of more than one '''group'''. | + | || |
+ | *A '''user''' can be a member of more than one '''group'''. | ||
*Those '''groups '''are called '''supplementary groups'''. | *Those '''groups '''are called '''supplementary groups'''. | ||
*These '''groups '''are assigned to the '''user''', to provide him additional '''access''' to resources. | *These '''groups '''are assigned to the '''user''', to provide him additional '''access''' to resources. | ||
Line 63: | Line 65: | ||
|- | |- | ||
|| Slide 9 | || Slide 9 | ||
− | || Let’s take an example.*'''User radha '''belongs to the '''CSE department'''. | + | || Let’s take an example. |
+ | *'''User radha '''belongs to the '''CSE department'''. | ||
*She is also a member of the '''music club '''and '''sports club'''. | *She is also a member of the '''music club '''and '''sports club'''. | ||
*In this scenario, '''CSE''' is the '''primary group '''for '''radha'''. | *In this scenario, '''CSE''' is the '''primary group '''for '''radha'''. | ||
Line 119: | Line 122: | ||
|- | |- | ||
|| Slide 10 | || Slide 10 | ||
− | || *Alternatively, we can mention a '''GID '''of our choice. | + | || |
+ | *Alternatively, we can mention a '''GID '''of our choice. | ||
*For this, we need to use '''hyphen gid''' option along with the '''addgroup command'''. | *For this, we need to use '''hyphen gid''' option along with the '''addgroup command'''. | ||
*'''GIDs''' in the range of''' 0 '''to''' 999''' are '''reserved''' for the '''system users'''. | *'''GIDs''' in the range of''' 0 '''to''' 999''' are '''reserved''' for the '''system users'''. | ||
Line 288: | Line 292: | ||
|| Notice, | || Notice, | ||
− | + | '''User radha''' is in group '''cse''' which has '''GID''' 1002 | |
That is the''' primary group''' for '''radha'''. | That is the''' primary group''' for '''radha'''. | ||
− | Next, there is the list of '''groups''',where '''user radha '''is member of. | + | Next, there is the list of '''groups''', where '''user radha '''is member of. |
Notice, along with '''primary group cse, radha''' is also a member of two '''supplementary groups music underscore club''' and '''sports underscore club.''' | Notice, along with '''primary group cse, radha''' is also a member of two '''supplementary groups music underscore club''' and '''sports underscore club.''' | ||
Line 329: | Line 333: | ||
|- | |- | ||
|| Slide 13: | || Slide 13: | ||
− | || So, remember*'''/etc/passwd''' shows '''primary group ID '''for a '''user''' | + | || So, remember |
+ | *'''/etc/passwd''' shows '''primary group ID '''for a '''user''' | ||
*'''/etc/group file''' shows list of '''usernames''' who have the''' group '''as a '''supplementary group''' | *'''/etc/group file''' shows list of '''usernames''' who have the''' group '''as a '''supplementary group''' | ||
Line 391: | Line 396: | ||
|| As an assignment- | || As an assignment- | ||
− | + | 1)Create two '''groups: ''' | |
− | + | #'''cultural ''' | |
− | + | #'''literature''' | |
|- | |- | ||
Line 399: | Line 404: | ||
Assignment(Cont.) | Assignment(Cont.) | ||
− | || | + | || |
− | + | 2)Now create a''' user ajay''' with | |
− | + | #'''Home directory''' as '''/home/ajay underscore dir ''' | |
− | + | #'''User id '''as''' 1090''' | |
− | + | #'''Primary group '''as '''cultural''' | |
− | + | #'''Supplementary group '''as '''literature''' | |
+ | #Add '''comments "Native: Mumbai"''' | ||
|- | |- |
Revision as of 16:51, 31 August 2018
Title of script: Assigning Groups on User Creation
Author: Antara Roy Choudhury
Keywords: group, primary group, supplementary group, assigning group, specify GID, /etc/group file
Visual Cue | Narration |
Slide 1: Introduction | Hello and welcome to the spoken tutorial on Assigning Groups on User Creation in Linux. |
Slide 2: Learning Objectives | In this tutorial we will learn about
We will do this through some examples. |
Slide 3: System requirement | To record this tutorial, I am using Ubuntu Linux 16.04 OS |
Slide:4 Prerequisite | To practice this tutorial,
|
Slide 5: | What is a group in Linux?
|
Slide 6: | Linux supports two types of groups.
|
Slide 7: |
|
Slide 8: |
More on access mechanism or permission will be discussed in subsequent tutorials. |
Slide 9 | Let’s take an example.
Let’s create this scenario in our system. |
First, we will create group CSE.
And we will use addgroup command in order to create this group. | |
Press Ctrl+Alt+T | Open the Terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard. |
Type
sudo su [Enter] |
Now, we should login as superuser or root user.
To do so type: sudo space su and press Enter. |
Type
Password of your account [Enter] |
Type the admin password and then press Enter. |
Highlight # prompt | Notice, our login prompt has changed to a hash symbol.
This indicates that we are in the root user mode. |
Only narration | Here onwards, please remember to press the Enter key after typing each command. |
Type
addgroup cse [Enter] |
Now type addgroup space cse |
Show the output
{Suppose output is Adding group cse (GID 1009)} |
This will create group cse.
Linux automatically allocates a Unique ID for each group that is created. Here, GID, that is Group ID is 1002. |
Slide 10 |
|
Let’s us create a group Music_club with the GID 1012. | |
Type:
addgroup -gid 1012 Music_club [Enter] |
On the terminal type:
addgroup space hyphen gid 1012 space Music underscore club Here type M is in capital letter. |
Show the output | Notice, it is showing some error.
Actually, we should have written m in lowercase letter. Let’s try that. |
Press Up key | Press the Up arrow key to get the previously executed command. |
Change Music_club to music_club [Enter] | Change capital M to m in lowercase letter. |
Show the output | The command is working now.
So, always remember to use lowercase letters while writing group names. |
Type
addgroup sports_club [Enter] |
Similarly let’s create another group sports underscore club.
This time no need to mention the GID. |
Now we have three groups cse, music underscore club and sports underscore club. | |
cat /etc/group
[Enter] |
How can we check the details of the created group?
|
Show file opened | There will be an entry in this file for every user on the system. |
slide
Highlight on the slide |
Each line has four fields separated by a colon symbol.
The first field is the name of the group. The second field is the encrypted password for the group. Third field shows the GID as a number. |
Highlight on the slide |
Fourth field contains the list of users that belong to that group separated by commas.
This list contains all users who have this group as a secondary group. |
Show file /etc/group
|
We can see the entries for cse, music underscore club and sports underscore club groups.
Notice, music underscore club has Gid 1012 which we mentioned during group creation. Here, the fourth field is empty for all the groups. This is because there are no members in these groups, as of now. The password field is x. We will discuss about the password field and list of members field in detail, in a separate tutorial on groups. |
Retain same screen | Now, how can we specify the primary and supplementary groups while creating the user?
Let us see an example. |
Type
adduser -ingroup cse radha [Enter] |
To specify that user radha belongs to the primary group cse, type:
adduser space hyphen ingroup space cse space radha |
Type
pass_radha [enter] |
Type the password as pass underscore radha and press Enter.
Retype the same password and press Enter. Type name as Radha with capital R. And proceed as we have done before. |
Show output | We have successfully created user radha with primary group cse. |
Highlight ingroup | So, you should use ingroup option to specify primary group’s name while creating the user. |
adduser radha music_club
[Enter] |
As we know, radha is a member of music underscore club.
So music underscore club will be the supplementary group for the user radha. Type adduser space radha space music underscore club |
Retain same screen | Remember.
To add supplementary groups using adduser command, you should have an existing user. |
Highlight
adduser -ingroup cse radha command executed previously |
Here, we have first created the user radha. |
Highlight
adduser radha music_club |
Then added radha to the supplementary group using adduser command. |
adduser radha sports_club | If you need to specify that radha is also a member of sports club type:
adduser space radha space sports underscore club |
id radha | Let’s check user radha’s details using id command.
Type id space radha |
Show the output | Notice,
User radha is in group cse which has GID 1002 That is the primary group for radha. Next, there is the list of groups, where user radha is member of. Notice, along with primary group cse, radha is also a member of two supplementary groups music underscore club and sports underscore club. |
Type
grep radha /etc/group [Enter] |
Now let’s check our /etc/group file for the entry of radha
Type: grep space radha space /etc/group |
Highlight appropriately in the output | Notice, you can see user radha is the member of groups music underscore club and sports underscore club
But not as a member of the primary group that is cse. So the group file will list only the supplementary groups in which the user is associated. |
Type
grep radha /etc/passwd [Enter] |
Check the /etc/passwd file for the details of the username radha.
Type grep space radha space /etc/passwd |
Show the output | Notice, the fourth field is 1002
It is the GID for the group cse. It is the primary group for radha. |
Slide 13: | So, remember
|
Slide 14: | Command id space username shows the details of both primary and supplementary groups |
Retain same screen | You can also specify the group id instead of group’s name while creating the user.
Let us create a user suraj and assign him to the group cse using the gid. We know group cse has GID 1002 |
Type
adduser -gid 1009 suraj [Enter] |
So type: adduser space hyphen gid space 1002 space suraj
You should use hyphen gid option to specify the group ID. Use pass underscore suraj as the password Retype the password Full Name as Suraj with S in capital letter. Proceed as we have done for the previous users. |
Highlight the output | We have successfully created user suraj with primary group cse. |
Type
exit and press Enter |
To exit from the root user access, type exit |
Retain same screen | This brings us to the end of this tutorial.
Let us summarize. |
Display Slide 15
Summary |
In this tutorial we learnt about-
|
Display Slide 16
Assignment |
As an assignment-
1)Create two groups:
|
Slide 17
Assignment(Cont.) |
2)Now create a user ajay with
|
Slide 18
Assignment(Cont.) |
3) Use the command id to check the user details
4) Check the details of user ajay in /etc/passwd and /etc/group files |
Slide 19: About Spoken Tutorial project | The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
Slide 20: Spoken Tutorial workshops | The Spoken Tutorial Project team conducts workshops and gives certificates.
For more details, please write to us. |
Slide 21: Forum for specific questions: | Please post your timed queries in this forum. |
Slide 22: Acknowledgement | Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
More information on this mission is available at this link. |
Slide 23: Thank You | The script has been contributed by Antara and this is Praveen from IIT Bombay signing off.
Thank you for joining. |