Topics to be Covered in todays blogpost:
How to add a user (useradd)?
How to delete a user (userdel)?
How to modify the user (usermod)?
How to add the group? (groupadd)?
How to delete a group? (groupdel)?
Files we will take a look at :
/etc/passwd
/etc/group
How to Create a user ?
useradd <username>
How to identify if the user is created ?
id <username>
when you add the user 'shan' , automatically group called 'shan' is created.as you can see in the below snip that user and group of 'shan' is 'shan'. Also 'shan' directory automatically gets created in home directory.
Question:
As you can see in the above snip that directory of victor has been created in home directory.
and user and group is 'victor' and 'QA' respectively.
How to delete a user ?
Commands:
userdel <name of user>
userdel -r (will remove home directory)
userdel -f (force delete even if the user is logged in)
Question:
How to delete user victor that we have created above? delete home directory for victor as well.
Answer:
How to modify the user?
How to add the user to new group, but default group will remain the same?
usermod -G <group_name> <user_name>
how to change the defaut group of the user?
usermod -g <group_name> <user_name>
How to add shan to the group QA ?
usermod -G QA shan
Default group of shan is shan ,if you add shan to QA group ,shan will be the part of 2 groups now.
How to change the default group of user shan to 'QA'?
usermod command options:
-m -d /home/newfolder : to move the content of the home folder to this new folder.
-p : we can use passwd command as well
-s : shell
-L -U : (lock /unlock the user)
How to create a group ?
groupadd <group_name>
How to add the group named 'TEST'?
we can check if the group named 'TEST' is created or not in /etc/group file as shown below:How to delete the group 'TEST'?if you see in the below snip ,group 'TEST' has been deleted from /etc/group file.
Note : /etc/passwd file will show the list of users we have created.
Comments
Post a Comment