How to create, modify, and delete users and groups in Linux

Admin

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.

  1. Creating a User:

    • To create a user, you can use the useradd command followed by the desired username:
      bash
      sudo 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.
  2. Modifying User Properties:

    • To modify user properties such as username, home directory, or shell, you can use the usermod command:
      bash
      sudo 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 usermod man page for additional options and details.
  3. Deleting a User:

    • To delete a user account, you can use the userdel command:
      bash
      sudo userdel username
  4. Creating a Group:

    • To create a group, you can use the groupadd command followed by the desired group name:
      bash
      sudo groupadd groupname
  5. Modifying Group Properties:

    • To modify group properties such as group name or group ID, you can use the groupmod command:
      bash
      sudo groupmod -n new_groupname old_groupname # Modify group name sudo groupmod -g new_groupid groupname # Modify group ID
  6. Deleting a Group:

    • To delete a group, you can use the groupdel command:
      bash
      sudo groupdel groupname

Remember to run these commands with administrative privileges (root or sudo access) to create, modify, or delete users and groups.

Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !