Linux-for-Sys-Ads/C2/Modifying-User-Account/English
Title of script: Modifying User Account
Author: Antara Roy Choudhury
Keywords: usermod, change, lock password, unlock password, lock account, unlock account, change home directory, change shell, change comments
Visual Cue | Narration |
Slide 1: Introduction | Hello and welcome to the spoken tutorial on Modifying User Account 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: | The command usermod is used to modify the attributes of an already created user account.
This is the syntax Here the options part is not mandatory This command supports many options. We will learn them through some examples. |
Retain same screen | Earlier in the series, we had created a user radha.
Now let’s modify the user account attributes of radha by using the usermod command. |
Press Ctrl+Alt+T | Open the Terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard. |
Type sudo su [Enter] |
First, we will 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 now 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 at the terminal:
id radha [Enter] |
We will check the user id and group information for user radha.
On the terminal type id space radha |
Show the output | Notice, user ID of radha is 1002 |
|
In order to modify user ID to 1100,
On the terminal we have to type- usermod space hyphen u in small letter 1100 radha |
Execute at the terminal: id radha [Enter] | Now once again, type id space radha.
Notice that the UID has been changed to 1100. |
usermod command can be used to modify a user’s primary and supplementary group. | |
Highlight the output of previous command | User radha belongs to primary group CSE
And supplementary groups music_club and sports_club. |
Slide 6A |
|
Slide 6B |
|
Type: addgroup electronics [Enter] |
Switch to the terminal
Type addgroup space electronics |
Show the output | Group electronics is added with GID 1006. |
Type
addgroup literature_club [Enter] |
Next, type addgroup space literature_club |
Show the output | Group literature_club is added with GID 1007. |
usermod -g electronics -G literature_club radha
[Do not press Enter] |
Now, to modify the primary and supplementary groups, type:
usermod space -g space electronics space -G in caps space literature_club space radha |
Highlight music_club and sports_club of the output of previous command | hyphen capital G option removes the user from previous supplementary groups
In this case, it removes from the previous supplementary groups |
Highliture literature_club
[Now press Enter] |
And adds the user to the new group literature_club |
Execute at the terminal:
id radha [Enter] |
Type id radha |
Show the output
Highlight appropriately |
Now we can see that the primary group is set to electronics.
And supplementary group is set to literature_club. |
Slide 7:
Add a user to a new supplementary group |
How can you add a user to a new supplementary group while retaining the previous groups?
|
usermod -a -G music_club radha [Enter] |
Say for example, user radha wishes to be in both music_club and literature_club groups.
For this type: usermod space hyphen a space hyphen G in caps space music_club space radha |
Execute at the terminal:
id radha [Enter] |
Once again type id space radha |
Show the output | Notice that user radha now belongs to two supplementary groups
music_club and literature_club |
usermod -l testmod radha | Suppose we now want to change the login name itself from radha to testmod.
To do this, on the terminal type the following: usermod space hyphen l space testmod space radha |
Now user radha has become user testmod. | |
grep testmod /etc/passwd | Let’s search for testmod’s details in /etc/passwd file.
Type grep space testmod space /etc/passwd |
Highlight appropriately | Notice that the login name or user name has changed but the home directory remains the same.
Ideally, we should rename the home directory to match the login name. |
There are 2 methods to do this. | |
Method 1:
We can manually rename the home directory to match the login name. Let me do that now. | |
Type mv /home/radha /home/testmod
[Enter] |
Type mv space /home/radha space /home/testmod
This command will rename directory radha to testmod. |
Type gedit /etc/passwd & [Enter] | Now, use any text editor to update the entry in /etc/passwd file.
I will be using gedit text editor. Type gedit space /etc/passwd space ampersand |
Modify /home/radha to /home/testmod | Now search for /home/radha
Replace it with /home/testmod |
Click to save >> close the file | Save and close the file. |
Back to terminal. | Press Ctrl C to stop the currently running process. |
Press Up key
Press Enter |
Press the Up arrow key until you get the previous grep command.
And press Enter. |
Show output | Notice that we have testmod as the new home directory for user testmod. |
Slide 8 | Method 2:
We can change the home directory for the user radha with the help of usermod command. |
Slide 8 | The syntax to change the home directory of user radha to the directory named testmod is as follows:
usermod space -m space -d space /home/testmod space radha |
This command will change the home directory of user radha to testmod | |
Slide 8 |
The new directory will be created, if it does not already exist. |
Slide 8 | Important note:
We should write hyphen d option immediately after the new directory name. Else we will get an error. |
I will not demonstrate this because we have already changed the home directory using method 1. | |
Now let’s learn how to modify the user’s login shell and comments field. | |
Highlight output of previous command | Notice that our current login shell is /bin/bash and we have “Radha” as comments. |
Type:
usermod -s /bin/sh -c "This is modified user" testmod [Enter] |
On the terminal type
usermod space hyphen s space /bin/sh space hyphen c space within double quotes This is modified user space testmod |
Press Up key | Press the Up arrow key to get previous grep command. |
Highlight shell and comments filed in the output | Notice, we have changed the values in shell and comments field. |
usermod -L testmod |
As a system admin you may need to lock a user account for various reasons, like violation of some rules by the user.
To lock the user testmod, type: usermod space hyphen L in Caps space testmod |
cat /etc/shadow [Enter] | Now type cat space /etc/shadow |
On doing so, we get an exclamation mark added before the encrypted password for user testmod.
So, no password will match it anymore. We have also seen this while locking password with passwd command. | |
Slide 9 |
|
Slide 10 | For that type
usermod space hyphen capital L space hyphen e space 1 space username It will prevent the user from logging in from any other source including ssh. I will skip the demonstration of this command. |
usermod -U testmod [Enter] | To unlock the account we have to type:
usermod space hyphen U in caps space testmod |
Press Up key twice
Press Enter |
Once again check the contents of /etc/shadow file
Notice, the exclamation mark is removed now. It means the password is not locked. |
Retain same screen | We have seen all the options supported by usermod command.
You can use the man command anytime to get details of usermod command. |
Type man usermod [Enter] | Type man space usermod |
Show the output
And scroll down |
Notice, all the details about this command as shown.
Type q to quit from this command. |
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. |
Slide 11 Summary | In this tutorial we learnt about-
|
Slide 12 | As assignment, modify user account amit such that
|
Slide 13 |
|
Slide 14
About Spoken Tutorial project |
The video available at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
Slide 15
Spoken Tutorial workshops |
The Spoken Tutorial Project team conducts workshops using spoken tutorials and gives certificates.
For more details, please write to us. |
Slide 17
Forum for specific questions: |
Pls post your timed queries in this Forum. |
Slide 18
Acknowledgement |
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
More information on this mission is available at this link. |
The script has been contributed by Antara
And this is Praveen from IIT Bombay signing off. Thanks for joining. |