User and Group administrations

From our last section you have learned System administration related commands. Whether its exam or real world senior first and top most work for a system administrator is user management. In Linux user and group management is done by these files.

Linux files responsible for User managements

/etc/shadow Store all the Linux password in MD5 encryptions format
/etc/passwd Store all user related information's
/etc/group Store all group related information's

Back-up Files

In this assignment we will modify these files. So it's better to take back-up before doing this assignment because your little mistake can crash Linux system.

#mkdir /backup
#cp /etc/passwd /backup
#cp /etc/group /backup
#cp /etc/shadow /backup 

linux User managements

Create user

useradd is used to create user. Several options are used with useradd command but you will learn about them in our next assignments. In this assignment you are going to learn what exactly happen in these files when a new user is added. First watch carefully last lines of these files.

#cat /etc/passwd |more
#cat /etc/shadow |more
#cat /etc/group |more 

Add a user.

#useradd vinita
#passwd vinita 

linux User managements

Now read these files again with cat command or you can use |grep switch to filter the output

#cat /etc/passwd |grep vinita
#cat /etc/shadow |grep vinita
#cat /etc/group |grep vinita
# cd /home
#ls –ld vinita 

linux User managements

User's entry in passwd

All these files are changed when a user is created in passwd file entries are done in following format separated by :

vinita users login name x password required to login 503 unique user id 504 unique group id /home/vinita users home directory /bin/bash user shell 

In shadow file entry is straight forward. Whatever showing beside the user name is the password of user vinita in MD5 encrypt format.

User's entry in group

Whenever you create a normal user, users primary group form same name is automatically created. As you can verify by looking in /etc/group. 504 is the unique group id.

User's home directory

Same as group, users home directory is also created in /home partition and user get the ownership of this directory.

How to create a user without password.

linux User managements

To create a user without password use –d switch .

#useradd nikki
#passwd -d nikki 

How to create a group.

To create group use groupadd commands. Group created by this command is called secondary group.

#groupadd test
#cat /etc/group |grep test 

How to add user in groups

To add user in this group use usermod commands

#usermod –G test vinita 

This command will make vinita user to member of test group.

How to delete secondary group

You can delete a group by groupdel commands

#groupdel test
#cat /etc/group |grep test 

You cannot delete users primary group until user exist for example

 #groupdel nikki 

How to delete User

userdel command is used to delete user. When a user is deleted user's primary group will automatically be deleted.

#userdel nikki
#groupdel nikki groupdel: group nikki does not exist. 

linux User managements

Whenever you delete user with userdel command. entry of user will be removed from these files. But users home folder and mail folder will not be deleted. As you can see in image. If you want completely remove user including his home folder and mail folder use –r switch with userdel commands.