Linux-for-Sys-Ads/C2/Modifying-User-Account/English-timed

From Script | Spoken-Tutorial
Revision as of 14:23, 7 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 Modifying User Account in Linux.
00:08 In this tutorial we will learn about usermod command
00:13 Modifying attributes of user account
00:17 Locking and unlocking password or account
00:21 We will do this through some examples.
00:25 To record this tutorial, I am using Ubuntu Linux 16.04 Operating System
00:33 To practice this tutorial, you should have gone through the Linux System Administration tutorials on this website and
00:42 You must have root access to your computer.
00:47 The command usermod is used to modify the attributes of an already created user account.
00:55 This is the syntax.
00:58 Here the options part is not mandatory.
01:03 This command supports many options.
01:06 We will learn them through some examples.
01:10 Earlier in the series, we had created a user radha.
01:15 Now let’s modify the user account attributes of radha by using the usermod command.
01:23 Open the terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard.
01:32 First, we will login as superuser or root user.
01:37 To do so, type sudo space su and press Enter.
01:44 Type your password and then press Enter.
01:48 Notice, our login prompt has now changed to a hash symbol.
01:54 This indicates that we are in the root user mode.
01:59 Here onwards, please remember to press the Enter key after typing each command.
02:05 We will check the user id and group information for user radha.
02:11 On the terminal type id space radha
02:17 Notice, user ID of radha is 1002
02:23 In order to modify user ID to 1100,
02:28 On the terminal we have to type- usermod space hyphen u in small letter space 1100 space radha
02:40 Now once again, type id space radha.
02:45 Notice that the UID has been changed to 1100.
02:51 usermod command can be used to modify a user’s primary and supplementary group.
02:58 User radha belongs to primary group CSE

And supplementary groups music_club and sports_club.

03:08 We will change the primary group from CSE to electronics.
03:14 We will also change the supplementary group to literature_club.
03:20 But we have not created the groups electronics or literature_club.
03:27 So, first we have to create these two groups.
03:31 Switch to the terminal.

Type addgroup space electronics

03:39 Group electronics is added with GID 1006.
03:45 Next, type addgroup space literature_club.
03:51 Group literature_club is added with GID 1007.
03:58 Now, to modify the primary and supplementary groups, type:

usermod space -g space electronics space -G in caps space literature_club space radha

04:18 hyphen capital G option removes the user from previous supplementary groups
04:25 In this case, it removes from the previous supplementary groups.
04:29 And adds the user to the new group literature_club
04:35 Type id space radha
04:39 Now we can see that the primary group is set to electronics.

And supplementary group is set to literature_club.

04:49 How can you add a user to a new supplementary group while retaining the previous groups?
04:56 For this, you should use -a option.
05:01 a option denotes append.
05:05 Say for example, user radha wishes to be in both music_club and literature_club groups.
05:15 For this type: usermod space hyphen a space hyphen G in caps space music_club space radha
05:29 Once again, type id space radha
05:34 Notice that user radha now belongs to two supplementary groups -

music_club and literature_club

05:44 Suppose we now want to change the login name itself from radha to testmod.
05:52 To do this, on the terminal type the following: usermod space hyphen l space testmod space radha
06:04 Now user radha has become user testmod.
06:09 Let’s search for testmod’s details in /etc/passwd file.
06:17 Type grep space testmod space /etc/passwd
06:26 Notice that the login name or user name has changed but the home directory remains the same.
06:34 Ideally, we should rename the home directory to match the login name.
06:40 There are 2 methods to do this.
06:43 Method 1:

We can manually rename the home directory to match the login name.

06:50 Let me do that now.
06:52 Type mv space slash home slash radha space slash home slash testmod
07:02 This command will rename directory radha to testmod.
07:09 Now, use any text editor to update the entry in slash etc slash passwd file.
07:18 I will be using gedit text editor.
07:22 Type gedit space slash etc slash passwd space ampersand
07:32 Now search for slash home slash radha
07:37 Replace it with slash home slash testmod
07:42 Save and close the file.
07:45 Press Ctrl C to stop the currently running process.
07:51 Now press the Up arrow key to get the grep command for user testmod.

And press Enter.

08:00 Notice that we have testmod as the new home directory for the user testmod.
08:08 Method 2: We can change the home directory for the user radha with the help of usermod command.
08:17 The syntax to change the home directory of user radha to the directory named testmod is as follows:

usermod space -m space -d space slash home slash testmod space radha

08:37 This command will change the home directory of user radha to testmod
08:44 -d is used to modify the directory for any existing user account
08:51 -m moves the contents of the existing home directory to the new home directory.
08:59 The new directory will be created, if it does not already exist.
09:05 Important note: We should write hyphen d option immediately after the new directory name.

Else we will get an error.

09:17 I will not demonstrate this because we have already changed the home directory using method 1.
09:25 Now let’s learn how to modify the user’s login shell and comments field.
09:32 Notice that our current login shell is /bin/bash and we have “Radha” as comments.
09:41 On the terminal type

usermod space hyphen s space slash bin slash sh space hyphen c space within double quotes This is modified user space testmod

10:00 Press the Up arrow key to get previous grep command.
10:05 Notice, we have changed the values in shell and comments field.
10:11 As a system admin you may need to lock a user account for various reasons, like violation of some rules by the user.
10:21 To lock the user testmod, type: usermod space hyphen L in Caps space testmod
10:31 Now type cat space slash etc slash shadow
10:38 On doing so, we get an exclamation mark added before the encrypted password for user testmod.
10:46 So, no password will match it anymore.
10:50 We have also seen this while locking password with passwd command.
10:56 It will lock only the access to password.
11:00 If you wish to lock the account itself, you should also set the expiry date to 1.
11:07 For that type usermod space hyphen capital L space hyphen e space 1 space username
11:19 It will prevent the user from logging in from any other source including ssh.
11:26 I will skip the demonstration of this command.
11:30 To unlock the account we have to type: usermod space hyphen U in caps space testmod
11:41 Once again check the contents of /etc/shadow file.
11:47 Notice, the exclamation mark is removed now.
11:51 It means the password is not locked.
11:55 We have seen all the options supported by usermod command.
12:00 You can use the man command anytime to get details of usermod command.
12:06 Type man space usermod
12:10 Notice, all the details about this command as shown.
12:16 Type q to quit from this command.
12:20 To exit from the root user access, type exit

And press Enter.

12:27 This brings us to the end of this tutorial.

Let us summarize.

12:33 In this tutorial we learnt about-

usermod command, Modifying attributes of user account, Locking and unlocking password or account

12:47 As assignment, modify user account amit such that

Primary group is electronics

12:56 Supplementary groups are music_club and literature_club
13:03 Set home directory as amit_newDir
13:09 Include comment "Stream Change Student"
13:13 Perform all the mentioned tasks in a single command.
13:18 Check the entry of user account amit in /etc/passwd and /etc/group files
13:29 The video available at the following link summarises the Spoken Tutorial project.

Please download and watch it.

13:38 The Spoken Tutorial Project team conducts workshops using spoken tutorials and gives certificates.

For more details, please write to us.

13:50 Pls post your timed queries in this Forum.
13:54 Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
14:00 The script has been contributed by Antara And this is Praveen from IIT Bombay signing off.

Thanks for joining.

Contributors and Content Editors

PoojaMoolya