Day 6/90: File Permissions and Access Control Lists in Linux ๐Ÿ” #90DaysOfDevOps

Kanav Gathe - Oct 23 - - Dev Community

Day 6: File Permissions and Access Control Lists ๐Ÿš€

Hello DevOps enthusiasts! ๐Ÿ‘‹ Welcome to Day 6 of the #90DaysOfDevOps challenge. Today, we're exploring file permissions and Access Control Lists (ACL) in Linux.

Task Solutions ๐Ÿ’ป

1. Basic File Permissions

# Create and check file
touch test_file.txt
ls -ltr test_file.txt

# Change permissions (owner only)
chmod 700 test_file.txt
# OR
chmod u+rwx,go-rwx test_file.txt

# Verify changes
ls -ltr test_file.txt
Enter fullscreen mode Exit fullscreen mode

2. Permission Management Script

#!/bin/bash

# Change permissions for multiple files
change_permissions() {
    for file in "$@"
    do
        chmod 644 "$file"
        echo "Changed permissions for $file"
    done
}
Enter fullscreen mode Exit fullscreen mode

3. ACL Implementation

# Create test directory
mkdir acl_test
cd acl_test

# Set ACL for user
setfacl -m u:user1:rx file1.txt

# Set ACL for group
setfacl -m g:group1:rw file1.txt

# View ACL
getfacl file1.txt
Enter fullscreen mode Exit fullscreen mode

4. ACL Permission Script

#!/bin/bash

set_acl_permissions() {
    local file=$1
    local user=$2
    setfacl -m u:$user:rw "$file"
    echo "Set ACL for $user on $file"
}
Enter fullscreen mode Exit fullscreen mode

5. Special Permissions

# Sticky Bit
chmod +t /shared_directory

# SUID
chmod u+s /usr/bin/script

# SGID
chmod g+s /shared_directory
Enter fullscreen mode Exit fullscreen mode

6. Permission Backup

#!/bin/bash

# Backup permissions
getfacl -R /path/to/directory > permissions.acl

# Restore permissions
setfacl --restore=permissions.acl
Enter fullscreen mode Exit fullscreen mode

Permission Types Explained ๐Ÿ“

  1. Basic Permissions

    • Read (r): 4
    • Write (w): 2
    • Execute (x): 1
  2. Special Permissions

    • SUID (4000)
    • SGID (2000)
    • Sticky Bit (1000)
  3. ACL Features

    • User-specific permissions
    • Group-specific permissions
    • Default permissions
    • Inherited permissions

Key Takeaways ๐Ÿ’ก

  • File permissions are crucial for security
  • ACLs provide granular access control
  • Special permissions serve specific purposes
  • Regular permission backups are important

Linux #DevOps #Security #90DaysOfDevOps


This is Day 6 of my #90DaysOfDevOps journey. Keep securing and learning!

. . . . . . . . . . . . . . .