How to create, modify and delete the user in Linux ?
Introduction
[edit]Managing user accounts on a Unix-like system involves various commands to create, modify, and delete users. Each command serves a specific purpose, from creating a user with specific attributes to modifying group memberships and ultimately removing the user account. In this guide, we'll walk through the commands necessary to create, manage, and delete user accounts on a Unix-like system.
Prerequisites
[edit]Before proceeding, ensure that you have administrative privileges on the system. Familiarity with basic Unix commands and system administration concepts will be beneficial.
Creating a User
[edit]To create a user with specific attributes such as a home directory, primary group, secondary group, expiration date, and shell, you can use the useradd command. Here's the syntax:
useradd -u <user_id> -g <primary_group_id> -G <secondary_group_id> -d <path_of_directory> -m -s <shell> -e <expire_date> <username>
After creating the user, you can verify the creation and view user information using the cat /etc/passwd command.
Assigning a Password: Once the user is created, you should assign a password to the account using the passwd command:
passwd <username>
Modifying Group Memberships: To modify the primary or secondary group memberships of a user, you can use the usermod command. Here are the commands to modify primary and secondary groups:
usermod -g <new_primary_group_id> <username> usermod -G <new_secondary_group_id> <username>
Renaming a User: To rename a user account, you can use the usermod command with the -l option:
usermod -l <new_username> <old_username>
After renaming the user, you can verify the changes using cat /etc/passwd.
Deleting a User: To delete a user account, you can use the userdel command. If you also want to remove the user's home directory, use the -r option:
userdel <username> userdel -r <username>
Conclusion
[edit]Managing user accounts is an essential aspect of system administration on Unix-like systems. With the commands outlined in this guide, you can create, modify, and delete user accounts according to your system's requirements. Always exercise caution when performing user management tasks, especially when deleting accounts or modifying system-level configurations.