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...

Linux Prepatching tasks

 Pre-patching tasks in a Linux environment are critical to ensuring a smooth and successful patching process. These tasks help in minimizing downtime, preventing issues during the patching, and ensuring the system's stability. Here’s a checklist of common pre-patching tasks you should perform: 1. Backup Critical Data Full System Backup : Perform a full system backup, including configuration files, databases, and critical application data. Verify Backup Integrity : Ensure that the backup is complete and can be restored if necessary. 2. Review Patch Notes Understand the Patch : Review the release notes and documentation for the patches you plan to apply. Understand what is being updated and any potential impact on your system. Check Dependencies : Verify that all dependencies for the patches are met, including hardware, software, and configuration requirements. 3. Check System Health Disk Space : Ensure there is sufficient disk space available, especially on /var , /tmp , and /boot ...