Managing users and groups in Linux involves creating, modifying, and deleting user accounts and group memberships. These tasks are typically performed through command-line tools.
To create a user, the useradd the command is used with the desired username. User properties like the home directory or login shell can be modified using the usermod command, and the userdel command is used to delete a user account.
For groups, the groupadd command creates a new group, while groupmod allowing modification of group properties such as the group name or ID. The groupdel command deletes a group.
Administrative privileges, such as root or sudo access, are required to perform these operations. It's crucial to consider the broader implications, like file ownership and permissions, before making changes to user and group accounts.
Creating a User:
- To create a user, you can use the
useraddcommand followed by the desired username:bashsudo useradd username - You can add additional options to specify parameters like home directory, login shell, user ID, etc. Check the command's man page (
man useradd) for more details.
- To create a user, you can use the
Modifying User Properties:
- To modify user properties such as username, home directory, or shell, you can use the
usermodcommand:bashsudo usermod -l new_username old_username # Modify username sudo usermod -d /new_home_dir username # Modify home directory sudo usermod -s /new_login_shell username # Modify login shell - Again, you can refer to the
usermodman page for additional options and details.
- To modify user properties such as username, home directory, or shell, you can use the
Deleting a User:
- To delete a user account, you can use the
userdelcommand:bashsudo userdel username
- To delete a user account, you can use the
Creating a Group:
- To create a group, you can use the
groupaddcommand followed by the desired group name:bashsudo groupadd groupname
- To create a group, you can use the
Modifying Group Properties:
- To modify group properties such as group name or group ID, you can use the
groupmodcommand:bashsudo groupmod -n new_groupname old_groupname # Modify group name sudo groupmod -g new_groupid groupname # Modify group ID
- To modify group properties such as group name or group ID, you can use the
Deleting a Group:
- To delete a group, you can use the
groupdelcommand:bashsudo groupdel groupname
- To delete a group, you can use the
Remember to run these commands with administrative privileges (root or sudo access) to create, modify, or delete users and groups.
