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 /etc/passwd

The /etc/passwd file is a text file in Linux systems that contains information about user accounts on the system. It is used by many system utilities and applications to look up user-specific information, such as user IDs, home directories, and default shells.

Here's a tutorial on the /etc/passwd file:

  1. Structure of /etc/passwd file:

    Each line in the /etc/passwd file represents a user and has the following format:

    username:password:UID:GID:GECOS:home_directory:shell
    
    • username: The name of the user
    • password: The password field, usually containing an 'x' when shadow passwords are in use (the actual encrypted password is stored in /etc/shadow)
    • UID: The user ID, a unique numeric identifier for the user
    • GID: The group ID, a unique numeric identifier for the user's primary group
    • GECOS: A comma-separated list of additional user information (e.g., full name, office location, phone number); often left empty or just contains the user's full name
    • home_directory: The user's home directory
    • shell: The user's default shell, such as /bin/bash or /bin/sh

    For example:

    john:x:1001:1001:John Doe:/home/john:/bin/bash
    
  2. Read the /etc/passwd file:

    Use the cat or less command to read the /etc/passwd file:

    cat /etc/passwd
    

    or

    less /etc/passwd
    
  3. Display information about a specific user:

    Use the grep command to display information about a specific user. Replace username with the actual name of the user you're looking for:

    grep 'username' /etc/passwd
    
  4. Extract the UID and GID of a user:

    To extract the UID and GID of a user, you can use the id command. Replace username with the actual name of the user:

    id username
    

    Alternatively, you can use the awk and grep commands together:

    grep 'username' /etc/passwd | awk -F: '{print $3, $4}'
    
  5. List all users on the system:

    To list all user accounts on the system, you can use the awk and cut commands together:

    awk -F: '{print $1}' /etc/passwd
    

    or

    cut -d: -f1 /etc/passwd
    

By understanding the /etc/passwd file and its structure, you can effectively manage user accounts, extract user information, and ensure proper permissions on your Linux system. Keep in mind that this file is readable by all users on the system, so it does not store sensitive information such as encrypted passwords. Instead, encrypted passwords are stored in the /etc/shadow file, which is only accessible to the root user.

  1. Viewing user information in /etc/passwd: The /etc/passwd file in Linux contains user account information. To view user information:

    cat /etc/passwd
    

    This displays a list of user entries with fields separated by colons.

  2. Modifying user entries in /etc/passwd: To modify user entries, open /etc/passwd in a text editor:

    sudo nano /etc/passwd
    

    Edit the fields for the desired user. Each field is separated by a colon.

  3. Adding and removing users in /etc/passwd: To add a user, use the useradd command:

    sudo useradd username
    

    To remove a user, use the userdel command:

    sudo userdel username