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

Linux basic commands

 Linux basic commands: du  -sh  *  |  sort  -h  -r   |  head  -n  40  :    list out first 40 files in the directory that are taking more space in the directory.  cd : change directory Is-l listing the items in long listing format  pwd : print working directory Is-I format: type :no of links:owner : group:size :month :day :time :name cd/: go to/directory whoami: tells us by which username we are logged in. touch jerry: creates the file named jerry in present working directory. cp jerry lex: copy the content of jerry file and paste it to lex file. vi text1: creates the file text1 and open it in vi editor mkdir superman: creates the directory called superman mkdir abc def  : creates 2 folder in one command. touch filename wont work in /etc/ folder if logged in by normal account. man cp: shows manual for cp command. echo "india is my country"> file1 puts the text in file1. rm filename: remove the filename  mv lex luther renames the file from lex to luther  mv luther /h

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 expected do