User Management

Tarih: 2026-06-15 | Kategori: Linux

Etiketler: Linux

User management in Linux operating systems is of vital importance for system security and efficient resource sharing. This section focuses on how to create, manage, and delete users in Linux.

What is a User in Linux?

In Linux systems, users are defined as individuals or entities performing various tasks by logging into the system. User management is crucial for controlled access, resource allocation, and overall system administration.

In Linux, a user is associated with a user account that has several attributes defining their identity and privileges within the system. These attributes include the username, UID (User ID), GID (Group ID), home directory, default shell, and password.

Types of Users

Linux supports two types of users: system users and regular users.

  • System users: Created by the system during installation and are used to run system services and applications.
  • Regular users: Created by an administrator and can access the system and resources based on their permissions.
  • Creating a User

    To create a user, use the `useradd` command. For example, to create a user named "john," use the following command:

    root@hackerbox:~$ useradd -u 1002 -d /home/john -s /bin/bash john
    

    This command creates a user account for john with a user ID (UID) of 1002, a home directory set as `/home/john`, and a default shell of `/bin/bash`.

    You can verify the newly created user account by running the `id john` command. This command shows the ID and group memberships for the john user.

    root@hackerbox:~$ id john
    

    uid=1002(john) gid=1002(john) groups=1002(john)
    

    User Attributes

    In Linux systems, user accounts have various attributes that define their properties and access privileges.

  • Username: A unique identifier for the user within the Linux system. For instance, John's username is `john`.
  • UID (User ID) and GID (Group ID): Each user account is associated with a UID and a GID. The UID is a numeric value assigned to the user, while the GID represents their primary group. For example, John's UID is 1002, and his primary group's GID could also be 1002.
  • Home Directory: A designated directory where the user's personal files and settings are stored. John's home directory is `/home/john`.
  • Default Shell: The default shell specifies the command interpreter used when the user logs in. This defines the user's interactive environment. John's default shell is set to `/bin/bash`, a popular shell in Linux.
  • Password: User accounts require passwords for access and authentication.
  • Group: Group membership determines which system resources the user can access and which other users can access the user's files.
  • In Linux systems, registered users are stored in the `/etc/passwd` file. You can display the contents of this file to see the list of users on the system.

    root@hackerbox:~$ cat /etc/passwd
    

    root:x:0:0:System Administrator:/root:/bin/bash
    ...
    john:x:1002:1002:John Doe:/home/john:/bin/bash
    

    The user list within the `/etc/passwd` file follows this format:

  • `john`: Username.
  • `x`: Contains the hashed password of the user. For security reasons, the password is stored in the `/etc/shadow` file, so this field is replaced with the character `x`.
  • `1002`: UID (User ID) of the user account, a unique numeric identifier assigned to the user by the system.
  • `1002`: GID (Group ID) of the user account, representing their primary group membership.
  • `John Doe`: GECOS field. This field is used to store additional information about the user, such as the full name or contact information.
  • `/home/john`: Home directory of the user account where the user's files and personal data are stored.
  • `/bin/bash`: Default shell of the user account, used to interpret commands entered by the user in the terminal.
  • Changing User Passwords

    User passwords can be easily changed using the `passwd` command. For example, to set a new password for the `john` user, use the following command:

    root@hackerbox:~$ sudo passwd john
    

    This command prompts you to enter a new password interactively. Note that nothing will appear on the screen as you type for security reasons. Simply type the new password and press ENTER.

    Deleting a User

    To remove a user named John and their associated files, use the `userdel` command.

    root@hackerbox:~$ sudo userdel john
    

    This command deletes the john user's account, including their home directory and all files owned by the user.