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/shadow (Shadow File)

The /etc/shadow file is a text file in Linux systems that stores encrypted password and aging information for user accounts. It provides an additional layer of security compared to the /etc/passwd file by ensuring that sensitive information such as encrypted passwords is only accessible to the root user.

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

  1. Structure of /etc/shadow file:

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

    username:encrypted_password:last_change:min_age:max_age:warn_period:inactive_period:expire_date:reserved
    
    • username: The name of the user
    • encrypted_password: The encrypted password of the user, or an exclamation mark '!' or asterisk '*' if the account is locked or disabled
    • last_change: The number of days since January 1, 1970, when the password was last changed
    • min_age: The minimum number of days before the user can change their password
    • max_age: The maximum number of days the password is valid before the user is forced to change it
    • warn_period: The number of days before password expiration when the user is warned about the impending expiration
    • inactive_period: The number of days after password expiration that the account is disabled
    • expire_date: The number of days since January 1, 1970, when the account will expire and become inaccessible
    • reserved: A reserved field, usually left empty

    For example:

    john:$6$7VbSRRXT$D7e9BsA/x8s7s1:18750:0:99999:7:::
    
  2. Read the /etc/shadow file:

    Use the cat or less command to read the /etc/shadow file as the root user:

    sudo cat /etc/shadow
    

    or

    sudo less /etc/shadow
    
  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:

    sudo grep 'username' /etc/shadow
    
  4. Extract the encrypted password:

    To extract the encrypted password for a specific user, use the awk and grep commands together. Replace username with the actual name of the user:

    sudo grep 'username' /etc/shadow | awk -F: '{print $2}'
    

By understanding the contents of the /etc/shadow file and how to analyze it, you can effectively manage user accounts and their passwords on your Linux system, ensuring a more secure environment. Always exercise caution when working with sensitive files like /etc/shadow to prevent accidental disclosure or unauthorized modification.

  1. Viewing and editing user passwords in /etc/shadow: The /etc/shadow file in Linux contains encrypted password information. To view or edit user passwords:

    sudo nano /etc/shadow
    

    Editing should be done cautiously to avoid compromising security.

  2. Securing user password information in /etc/shadow: Secure /etc/shadow by ensuring proper file permissions. It should be readable only by privileged users (root).

    sudo chmod 400 /etc/shadow
    
  3. Tools for manipulating /etc/shadow entries in Linux: Tools like passwd, chage, and usermod are used to manipulate user password information in /etc/shadow. For example:

    sudo passwd username
    

    This command allows changing the password for a user.