DEV Community

Devon Argent
Devon Argent

Posted on

Day 4: Deciphering the "rwxr-x---" Mystery (Linux Permissions) πŸ›‘οΈ

Day 4 of my #1HourADayJourney. Today, I moved from just creating files to securing them. In the world of Database Engineering, knowing exactly who can read, write, or execute your data files is the foundation of security.

πŸ› οΈ Today's Technical Lab

I practiced how to control access to files using two powerful commands: chown and chmod.

1. Changing Ownership (chown)

To change who owns a file or a directory. Since this is an administrative task, I had to use sudo.

# Changing owner to 'user1' and group to 'group1'
sudo chown -R user1:group1 target_file

# Verify the change
ls -l target_file

Enter fullscreen mode Exit fullscreen mode

The -R flag is used for "Recursive" β€” applying the change to everything inside a directory.

2. The Octal Magic (chmod)

I practiced setting permissions using the numerical (octal) method. I used 750 as a test:

sudo chmod 750 target_file

Enter fullscreen mode Exit fullscreen mode

Breakdown of 750:

7 (User): Read + Write + Execute (Full access)

5 (Group): Read + Execute (No Write)

0 (Others): No access at all (Strict security)

3. Symbolic Tweaking

Sometimes you don't want to reset everything; you just want to add or remove one specific permission.

sudo chmod g+w target_file  # Adding 'Write' permission to the Group
sudo chmod g-x target_file  # Removing 'Execute' permission from the Group
Enter fullscreen mode Exit fullscreen mode

Follow my journey: #1HourADayJourney

Top comments (0)