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

Post build configurations on Redhat VM

  ************************************* Post build configuration on Linux VM: ************************************* Set the hostname. hostnamectl set-hostname <Servername> ***************************************** Network configuration : Make sure VM gets the ipv4 ip address either from DHCP or assign the static ip address to it.   Question : How to assign the static ip address to the linux machine using the nmcli ?  Answer: fire the below commands: nmcli device nmcli connection modify enpos3 ipv4.addresses 10.253.1.34/24 nmcli connection modify enpos3 ipv4.gateway 10.253.1.1 nmcli connection modify enpos3 ipv4.method manual nmcli connection modify enpos3 ipv4.dns 8.8.8.8 nmli connection down enpos3 nmcli connection up enpos3 ip address show enpos3 nmcli connection show ************************†****************** Register to RHΝ. Register to redhat network if the linux vm is redhat vm. subscription-manager register --org <org>  --activationkey <activat...

AWS cloud practitioner notes

 AWS Certified cloud practitioner: What is cloud computing? cloud computing is the on demand delivery of the compute power, database storage, applications and other IT resources through a cloud services platform with pay-as-you-go pricing. you can provision exactly the right type and size of the computing resources you need. you can access many resources as you need almost instantly like servers, storage,databases and application services as well. Amazon web services owns and maintains the network connected hardware required for these application services, while you provision and use what you need via a web application. ***************************************** Deployment models of Cloud: Private Cloud: Cloud service used by a single organisation, not exposed to the public. complete control. security of the sensitive applications meeting specific business needs. ********************** Public Cloud: Cloud resources owned and operated by the third party. cloud service provider delive...