Skip to main content

Linux user account management.



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:
How to create a user called 'victor' who is the part of QA team ,whose group is 'QA' ,shell type is '/bin/bash'? Also we want directory called 'victor' to be created in the home directory.
Answer:
useradd -g QA -s /bin/bash -c "Part of QA Team" -m -d /home/victor victor



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 ?

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

Popular posts from this blog

patching tasks

 Patching a Linux system is a critical task to ensure that the system remains secure, stable, and up-to-date with the latest features and fixes. Here’s a comprehensive guide to the tasks involved in Linux patching: 1. Pre-Patching Preparation Backup System : Ensure you have a full system backup, including critical data, configuration files, and applications. Test the backup to verify its integrity. Check Disk Space : Verify that you have enough disk space, particularly on /var , /tmp , and /boot partitions. Review Current Patch Level : Determine the current patch level and installed packages using package management tools like yum , apt , dpkg , or rpm . Check System Logs : Review system logs to identify any issues that might affect the patching process. Test in a Staging Environment : If possible, apply patches in a staging environment that mirrors production to identify potential issues. Notify Stakeholders : Inform stakeholders about the scheduled maintenance window and expecte...

Associate cloud Engineer notes

 google cloud offers below services:  compute  storage big data  machine learning  application services at the end of this notes you will be able to :  identify the value of the google cloud products  use application deployment environment on google cloud use google storage options  interact with google cloud service describe the ways in which customers use google cloud .   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. TOPICS:  cloud computing  IAAS ,PAAS,SAAS pricing and billing google cloud hierarchy  IAM VPC  compute engine scaling virtual machines through load balancer cloud DNS and CDN  google cloud storage options  storage classes and data transfer  cloud SQL  cloud spanner  Firestore Bigtable  comparing storage optio...