ITclub

العودة إلى Linux
محاضرة 5

User and Group Management (CLI)

كيفية إضافة وحذف وتعديل المستخدمين (Users) والمجموعات (Groups) من سطر الأوامر.

ملخص المحاضرة

🐧 Lecture 5: User and Group Management (CLI)

This lecture provides a detailed guide on how to manage users and groups using only the command line, which is essential for server administration.

User Management Commands

  • useradd: Creates a new user account.
    • sudo useradd a_user: Creates the user but does not create a /home/a_user directory.
    • sudo useradd -m -s /bin/bash a_user: The -m flag creates the user's home directory. The -s /bin/bash sets their default shell.
  • passwd: Sets or changes a user's password.
    • sudo passwd a_user: Prompts you to enter and retype a new password for 'a_user'.
  • userdel: Deletes a user account.
    • sudo userdel a_user: Deletes the user, but leaves their home directory and files behind.
    • sudo userdel -r a_user: The -r (recursive) flag deletes the user and their home directory with all its contents.
  • cat /etc/passwd: This command lists all user accounts on the system, showing their user ID, group ID, and home directory path.

Group Management Commands

Groups are used to control permissions for multiple users at once.

  • groupadd: Creates a new group.
    • sudo groupadd developers: Creates a group named 'developers'.
  • groupdel: Deletes a group.
    • sudo groupdel developers: Deletes the 'developers' group.
  • usermod: Modifies an existing user. It's used to add a user to a group.
    • sudo usermod -aG developers a_user: Adds 'a_user' to the 'developers' group. The -aG flags mean "append" (so you don't remove them from other groups) and "Groups".
  • gpasswd: Manages group settings.
    • sudo gpasswd -d a_user developers: Removes 'a_user' from the 'developers' group.
  • groups: Lists all groups a specific user belongs to.
    • groups a_user: Shows all groups for 'a_user'.
  • cat /etc/group: This command lists all groups on the system and shows which users are members of each.