๐ค User Management in Linux: Why It's Vital ๐ง
Managing users in a Linux system is fundamental to maintaining a secure and organized environment. User management involves creating, modifying, and deleting user accounts and their permissions. Let's dive into why user management is crucial and how it can be achieved efficiently. ๐
๐จโ๐ป Common User Management Tasks:
Different ways to add a Linux user
sudo useradd -g <group_name> -s <shell> -c "<description or comments>" -m -d <home_directory_of_user> <username>
Example:
As we have given all the options to useradd command in the above example but it is not mandatory to provide all the options to the useradd command (group name, comments, shell name and home directories are optional to use with useradd command).
If we don't provide a group name while adding a user it will create a self-group as per the username given in the command, if we don't provide a shell name it will configure a default shell (/bin/sh or /bin/bash..etc based on our default shell in our system) to the user, likewise, if we do not provide a home directory along with useradd command it will create a home directory with username itself (/home/<username>)
Example:
sudo useradd <username>
We can observe as given in the screenshot - even if we have not provided the group name, home directory and shell name, a new group ID (1006) got created and assigned to raygurudeo user and likewise /bin/sh shell configured and /home/ragurudeo (home directory) created by default.
How to set a Linux user password
Linux stores encrypted user's password in /etc/shadow.
We can set the user's password using the below command:
sudo passwd <username>
Example:
How to delete a user in Linux
sudo userdel -r <username>
It will delete a Linux user along with the user's home directory however -r flag is not mandatory if we do not use -r it will delete the user but the user's home directory will not be deleted.
Example:
We can observe that we have the user's home directory listed as raygurudeo and once we have deleted the user, home directory also got deleted.
Thank you !