Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux Users And User Groups

In Linux, users and user groups are essential concepts for managing system access and resources. Users represent individual accounts with unique login credentials, while groups allow multiple users to share access to files, directories, and other system resources. This tutorial will cover an overview of users, user groups, and their management in Linux.

Linux users

A user in Linux is an individual account with a unique identifier (UID) that allows someone to log in and access system resources. Each user has a username, password, and additional information such as their full name, home directory, and default shell.

There are two main types of users in Linux:

  1. Regular users: These users have limited access to system resources and typically can't perform administrative tasks without elevated privileges.

  2. Superusers (root user): The root user, or superuser, has unrestricted access to the entire system and can perform any action without limitations. The root user should be used with caution, as mistakes can lead to serious system damage.

Linux user groups

User groups in Linux are collections of users that can be used to manage access to files, directories, and other system resources. Each group has a unique group identifier (GID) and a name. Users can belong to one primary group and multiple secondary groups.

Groups are especially useful for managing permissions on shared resources, as you can grant or restrict access to a group instead of managing each user individually.

Managing users

There are several commands for managing users in Linux:

  1. useradd: Creates a new user account.
  2. usermod: Modifies an existing user account.
  3. userdel: Deletes an existing user account.
  4. passwd: Sets or changes a user's password.

Managing groups

Commands for managing groups in Linux include:

  1. groupadd: Creates a new group.
  2. groupmod: Modifies an existing group.
  3. groupdel: Deletes an existing group.
  4. gpasswd: Sets or changes a group's password.

Viewing user and group information

To view information about users and groups in a Linux system, you can use the following files:

  1. /etc/passwd: Contains user account information, such as usernames, UIDs, default shells, and home directories.
  2. /etc/shadow: Holds encrypted user passwords.
  3. /etc/group: Contains group information, including group names and GIDs.
  4. /etc/gshadow: Holds encrypted group passwords.

You can use tools like cat, grep, and less to view or search for information in these files.

Changing user and group ownership

To change the owner or group of a file or directory, you can use the chown and chgrp commands:

  1. chown: Changes the owner of a file or directory.
  2. chgrp: Changes the group of a file or directory.

Managing file permissions

File permissions in Linux are controlled using a combination of owner, group, and other user permissions. The chmod command allows you to change file permissions for the owner, group, and others.

In conclusion, users and user groups in Linux are essential for managing access to system resources. By creating and managing users and groups, you can maintain a secure and organized environment for your system's resources. Understanding the various commands for managing users, groups, and file permissions will help you effectively administer a Linux system.

  1. How to create a user in Linux:

    • Description: Use the useradd command to create a new user in Linux.
    • Code:
      # Example: Creating a new user
      sudo useradd username
      
  2. Managing user passwords in Linux:

    • Description: Use the passwd command to manage user passwords, set or change passwords.
    • Code:
      # Example: Setting/changing a user password
      sudo passwd username
      
  3. Viewing user details and attributes in Linux:

    • Description: Use the id or finger command to view user details and attributes.
    • Code:
      # Example: Viewing user details
      id username
      
  4. Creating and managing user groups in Linux:

    • Description: Use the groupadd command to create a new group in Linux.
    • Code:
      # Example: Creating a new group
      sudo groupadd groupname
      
  5. Adding users to groups and group permissions:

    • Description: Use the usermod command to add users to groups, and manage group permissions with chmod.
    • Code:
      # Example: Adding a user to a group
      sudo usermod -aG groupname username
      
  6. Changing user passwords and policies:

    • Description: Use the passwd command to change user passwords, and manage password policies in /etc/security/pwquality.conf.
    • Code:
      # Example: Changing a user password
      sudo passwd username
      
  7. Troubleshooting user and group-related issues in Linux:

    • Description: Troubleshooting may involve checking system logs, verifying permissions, or addressing errors encountered during user or group management.
    • Code:
      # Example: Troubleshooting user/group issues
      sudo journalctl | grep username