Day 6 : File Permissions and Access Control

Naushad KhanNaushad Khan
3 min read

Hello everyone! On Day 6 of my #90DaysOfDevOps challenge, I learned about file permissions and access control lists (ACL) in Linux. These are crucial concepts for managing who can access and change files on a system. Here’s what I did today:

What Are File Permissions? 🛡️

In Linux, every file has permissions that decide who can read, write, or run it. There are three categories of users:

  1. Owner: The person who created the file.

  2. Group: Other users who have special access to the file.

  3. Others: Everyone else who uses the system.

Tasks for the Day:

1. Create a File and Check Permissions

I created a simple file and used this command to check the permissions:

ls -ltr

This showed me who can access the file and what they can do with it.

2. Change Ownership and Permissions

  • I used chown to change who owns the file:
chown newowner filename.txt
  • I used chgrp to change the group permissions:
chgrp newGroup filename.txt
  • I used chmod to change the file's permissions. For example, to give only the owner read and write permissions:
chmod 600 filename.txt

3. Learn About Access Control Lists (ACL)

ACLs give more detailed control over who can access files. I used these commands:

  • Set permissions for a specific user:
setfacl -m u:username:rwx my_directory
  • Check the ACL permissions:
getfacl my_directory

Extra Tasks:

4. Change Permissions for Multiple Files

I wrote a script to change permissions for all files in a directory at once:

#!/bin/bash 
echo "Enter permission (e.g., 755):" 
read perm 
chmod $perm * 
echo "Permissions updated for all files."

5. Set ACL for a User via Script

Another script I made sets ACL permissions for a user on a file:

#!/bin/bash 
echo "Enter the filename:" 
read filename 
echo "Enter the username:" read username 
setfacl -m u:$username:rw $filename 
echo "ACL set for $username on $filename."

6. Learn About Sticky Bit, SUID, and SGID

I explored some special permissions:

  • Sticky Bit: Only the file owner can delete files in a directory.
chmod +t /shared/directory
  • SUID: Files can run with the file owner’s permissions.
chmod u+s /usr/bin/someprogram
  • SGID: Files in a directory inherit the group of that directory.
chmod g+s /shared/directory

Backup and Restore File Permissions 💾

I also wrote scripts to back up and restore file permissions:

  • Backup permissions:
ls -l > permissions_backup.txt
  • Restore permissions:
while read line; do chmod $line; done < permissions_backup.txt

Final Thoughts🎶

Today’s tasks were all about controlling file access in Linux, which is super important for keeping systems secure. I’m learning so much as I continue this journey!

1
Subscribe to my newsletter

Read articles from Naushad Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Naushad Khan
Naushad Khan

DevOps engineer with a passion for automation, CI/CD, and cloud platforms like AWS. I bridge dev and ops, optimizing workflows and sharing insights through technical blogs. Let’s automate the future! 🌐⚙️