Linux-for-Sys-Ads/C2/Creating-user-account/English

From Script | Spoken-Tutorial
Revision as of 14:34, 31 August 2018 by Pravin1389 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of script: Creating User Account

Author: Antara Roy Choudhury

Keywords: Creating user account, Different options, Specify user ID, Specify home directory, Specify login shell, Specify comments, /etc/passwd, /etc/shadow


Visual Cue Narration
Slide 1: Introduction Hello and welcome to the spoken tutorial on Creating User Account in Linux.
Slide 2: Learning Objectives In this tutorial we will learn about


  • Creating user account with different options
  • /etc/passwd file
  • /etc/shadow file


Slide 3: System requirement To record this tutorial, I am using Ubuntu Linux 16.04 OS
Slide:4 Prerequisite To practice this tutorial, *You should have gone through the Linux tutorial series on this website.
  • And you must have root access to the computer.


Slide 5: In an earlier tutorial on basics of system administration, we have learnt
  • To add a user using the following command:

adduser space option space username*Please note that the option field here, is not mandatory.

  • We will elaborate on the option field in this tutorial.
Press Ctrl+Alt+T Open the Terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard.
Type

sudo su

[Enter]

First, you should login as superuser or root user.

To do so type: sudo space su and press Enter.

Type

Password of your account

[Enter]

Type your 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.

Slide with a block diagram to explain the scenario Now, let’s consider a scenario of a college.

We will have students, departments, etc.

As a system administrator, you should first create a user account for individual students.

adduser amit

[Enter]

Let’s add one user say Amit using adduser command.

So, on the terminal type:

adduser space amit and press Enter

Type

pass_amit

[Enter]

It will prompt us to type the password for the user Amit.

Let’s type pass underscore amit and press Enter.

Retype the same password

[Enter]

Retype the same password and press Enter.
Type

Amit

[Enter]

When it prompts for the Full Name field, type the name of the user as Amit with A in caps.

Press Enter.

Leave the other fields empty by pressing the Enter key.

Press Y Press Y to confirm that the information you provided is correct.

Press Enter

On getting # prompt back So, we got back our root command prompt.

The user amit is now created.

Highlight appropriately in the output of previous command Linux automatically assigns a UID or User ID to the user.
Highlight appropriately in the output of previous command It also creates a home directory for the user in the system’s home folder.

In this case, it is /home/amit

Highlight appropriately in the output of previous command A group is also created with the same name as the username of the user.
Slide 6a: Now, say *we want a customized user ID or group
  • Or a home directory other than the default one
  • Or we want to change the default login shell
Slide 6b: *adduser supports options for each of these requirements.
  • Also you can combine multiple options to set multiple values in a single command.
Slide 7: *Hyphen u option is used to set user ID
  • Hyphen home sets user home directory
  • Hyphen shell sets the login shell for the user
  • Hyphen c option is used to mention comments
Slide 8: Let us take an example.

Say we want to add a user Kaushik with *user ID as 1050

  • home directory as testdir
  • login shell as /bin/sh
  • Also add “Kaushik is a re-registered student” in the comments.
Type:

adduser -u 1050 -home /home/testdir/ -shell /bin/sh

-c "Re-Registered student"

kaushik

[Enter]

Switch to the terminal.

Let me clear the terminal.

Type the command as shown here

Press Enter.

Type

pass_kaushik

[Enter]

It will ask you to enter the password for Kaushik.

I will type the password as pass underscore kaushik

press Enter.

Type

pass_kaushik

[Enter]

Retype the same password and press Enter.
Type Kaushik

[Enter]

Give the Full Name of the user as Kaushik with K in caps

press Enter.

Press Enter And proceed as we have done before.
Show the output So, the user kaushik is created now.
Type:

ls /home/

[Enter]

Now type ls space /home and press Enter.


Notice, we have a new directory testdir.

Slide 9: How can we view other information such as user ID, login shell etc.?*In Linux, all configuration files are stored in simple text files.
  • /etc/passwd file contains entire information about all the user accounts.
cat /etc/passwd

[Enter]

Let us have a look at the /etc/passwd file.

Switch to the terminal

Type cat space /etc/passwd and press Enter.

Show file opened

And scroll down until you see user amit and kaushik

Highlight rows

There will be an entry in this file for every user on the system.

Our passwd file shows this line for user Amit.

Each line has seven fields separated by colon.

Let us understand the fields one by one.

Slide *The first field is the username amit.
  • Remember, username should start with a lowercase letter
  • Followed by any number of lowercase letters or digits
  • No special character other than underscore is allowed in the username

You should remember this while you are creating a user account

Slide The second field is for password.

An x character indicates that the encrypted hash password is stored in the file /etc/shadow.

Slide The third field is user ID for that particular user.
Slide *User id 0 is reserved for root user.
  • User ids upto 999 are reserved for other administrative or system users.
  • Real user account id starts from 1000.
  • So, you should specify a number more than 1000 in the adduser command.
Slide The fourth field stores the primary group id for the user.

At the fifth place, we have the comments field.

It basically stores information about the user such as name of the user, room number, phone number, etc.

Slide The sixth field indicates the home directory for the user.

At the end, we have the login shell of the user.

Switch to terminal and highlight the rows for amit and kaushik Notice that, we have default values set for user Amit.

However, user kaushik is created with our customized values.

Type

cat /etc/shadow

Now, let’s have a look at the /etc/shadow file, where the encrypted passwords are stored.

Type cat space /etc/shadow and press Enter.

Show the output and highlight In this file, every line has information about a particular user.

And each line contains various fields separated by colon.

The first field is username, which must correspond to username field in /etc/passwd file.

(Suppose the entry looks like this

Amit:yh65fgtr)

Then highlight yh65fgtr

Notice, the second field is the encrypted password for that user.

Let us skip the other fields for now.

Type exit and press Enter To exit from the root user access, type exit and press Enter.
Retain same screen This brings us to the end of this tutorial.

Let us summarize.

Display Slide 16:

Summary

In this tutorial we learnt about-*Creating user account with different options like
    • Specific user id
    • Specific Home Directory
    • Specific shell
  • And adding comments
Display Slide 16:

Summary

We also learnt about some of the fields in the */etc/passwd and
  • /etc/shadow files
Slide 17:

Assignment

As an assignment

Create user ankit with *User ID as 1500

  • Home directory named ankit underscore newdir
  • Login shell as /bin/csh
Slide 18: *Include “Hostel 15” in the comment
  • Use a single command to perform all the tasks
  • Check the /etc/passwd file for the details of user account ankit
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: Forum for specific questions: Do you have questions in this Spoken Tutorial?

Please visit this site.

Choose the minute and second where you have the question.

Explain your question briefly.

Someone from our team will answer them.

Slide: Forum for specific questions: The Spoken Tutorial forum is for specific questions on this tutorial.

Please do not post unrelated and general questions on them.

This will help reduce the clutter.

With less clutter, we can use these discussion as instructional material.

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.

Contributors and Content Editors

Nancyvarkey, Pravin1389