Day-6:Shell ring a bell

Today embarks as Day-6 of 90 Days of DevOps

Β·

7 min read

Day-6:Shell ring a bell

INTRODUCTION

Hey there, fellow DevOps daredevils! 🌟

Picture yourself as a DevOps wizard, typing away commands like a pro, casting spells to make your deployment process smoother than a buttered dolphin slide! 🐬 Oh, the enchantment you'll weave when you realize you can automate repetitive tasks and banish those pesky manual errors to the land of forgotten bugs! πŸͺ„πŸœ

Shell Scripting is like wielding a magical wand in the world of DevOpsπŸšπŸ’». With just a few lines of commands, you'll be unleashing the power of the command line to automate tasks, tame the wildest servers, and conjure up mystical solutions in no time! πŸ§™β€β™‚οΈβœ¨

Title: File Permissions on Linux:πŸ“œ

Hey there, fellow Linux adventurers! Welcome to the comically informative guide on File Permissions! πŸŽ‰

So, you're probably wondering, "What on Earth are file permissions, and why do they sound as serious as a penguin trying to tango?" 🐧 Fear not, my curious comrades, for we're about to embark on a hilarious journey through the whimsical world of Linux file permissions!

Chapter 1: Permission-Palooza

Imagine your files and folders are like secret kingdoms, and the all-powerful Linux system plays the role of a benevolent ruler. 🀴 To maintain order and harmony in the digital realm, the ruler bestows three mystical permissions upon the inhabitants:

  1. Read: The power to peek inside a file, but not modify it – think of it as window shopping for data.

  2. Write: The magical ability to modify, edit, and even erase files – it's like being the royal scribe with a quill that never runs out of ink!

  3. Execute: The ultimate command to run scripts and programs, turning you into a Linux wizard capable of casting spells and performing digital acrobatics! πŸ§™β€β™€οΈ

Chapter 2: Meet the Permission Characters

Picture a lively masquerade ball where the guest list is filled with characters representing the three permission groups:

  1. User (a.k.a. Owner): The wise ruler of a file or folder, with complete control over the kingdom's destiny. Think of them as the ultimate monarchs with exclusive access to all three permissions!

  2. Group: A fellowship of loyal subjects who share similar interests and permissions. Imagine them as a quirky bunch of pals, each with their own unique skillset and privileges.

  3. Others: The rowdy bunch of digital bystanders – everyone who's not part of the User or Group. They have limited access and can only dream of the day they become royalty!

Chapter 3: The Magical Chant of CHMOD

Now, my friends, it's time to learn the enchanting spell that grants and revokes permissions – the CHMOD incantation! πŸͺ„

The magic formula goes like this: chmod [permissions] [file/folder].

You can use numbers (ranging from 0 to 7) or symbols (like "rwx") to cast your permission spell.

  • 0: 🚫 None – Permission denied, the door to the kingdom stays locked!

  • 1: πŸ“– Execute – The power to run scripts and unleash digital fireworks!

  • 2: πŸ“ Write – The ability to modify and update files at will!

  • 3: πŸ“– πŸ“ Execute + Write – A combo of both permissions, as unstoppable as a caffeinated squirrel!

  • 4: πŸ“š Read – The gift of peering into the file's secrets!

  • 5: πŸ“– πŸ“š Execute + Read – The ultimate knowledge seekers, like cyber sages!

  • 6: πŸ“ πŸ“š Write + Read – A force to be reckoned with, rewriting files with wisdom!

  • 7: πŸ“– πŸ“ πŸ“š Execute + Write + Read – The almighty overlords, wielding power over all aspects of the digital realm!

Chapter 4: Permission Pranks

Ah, you thought we'd forgotten to add some mischief into the mix? Not a chance! Here are a few permission pranks you might encounter in your Linux adventures:

  1. The "Oops, I Did It Again" Scenario: Setting permissions to 777 on a sensitive file, making it accessible to everyone, including pesky hackers!

  2. The "Where's Waldo?" Mystery: Accidentally misplacing a critical file by forgetting the correct permission combination. Time to summon the digital detectives!

TASK

Now, grab your favorite keyboard and let's get scripting! πŸŽΆπŸŽΉπŸ“

Steps To Follow:

Step 1: Create the Shell Script Open your favorite text editor, whether it's Vim, Nano, or any other, and create a new file named "file_details.sh".

Step 2: Write the Script Copy and paste the following code into the "file_details.sh" script:

#!/bin/bash

# Step 1: Create a simple file named "my_file.txt"
touch my_file.txt

# Step 2: Assign permissions to the file for three categories of users
# The permissions are as follows:
#   - Owner: Read, Write, Execute (rwx)
#   - Group: Read, Execute (rx)
#   - Others: Read (r)

chmod u+rwx my_file.txt
chmod g+rx my_file.txt
chmod o+r my_file.txt

# Step 3: Use 'ls -ltr' to see the details of the file
ls -ltr my_file.txt

Step 3: Save the Script Save the "file_details.sh" script and close your text editor.

Step 4: Make the Script Executable To run the script, you need to make it executable. Open your terminal, navigate to the directory where the script is located, and execute the following command:

chmod +x file_details.sh

Step 5: Run the Script Now that the script is executable, you can run it with the following command:

./file_details.sh

The script will create a simple file named "my_file.txt" and then assign permissions to the file for different categories of users: Owner, Group, and Others. Finally, it will display the details of the file using the 'ls -ltr' command.

You'll be able to see the permissions in the output of the 'ls -ltr' command. It will look something like this:

-rwxr-xr-- 1 username groupname 0 Jul 21 2023 my_file.txt

In this example, the Owner has Read, Write, and Execute permissions (rwx), the Group has Read and Execute permissions (rx), and Others have Read permission (r).

ACL IN LINUX

Now, we're delving into the intriguing realm of Access Control Lists (ACL) on Linux, a hidden gem that empowers you to fine-tune file permissions like never before. Forget the traditional one-size-fits-all approach – with ACL, you can grant specific users special access while keeping others at bay. πŸšͺπŸ”’

To embrace this newfound power, use the magical commands "setfacl" and "getfacl" These Linux wizards will help you create and manage ACL entries with ease, allowing you to sculpt access privileges to your heart's content. Let's elevate your Linux game and unlock the true potential of ACL! πŸ’»πŸ”“

setfacl: This command is used to set Access Control Lists (ACL) for files and directories on Linux.

Syntax:setfacl

setfacl -m <permissions>:<user_or_group>:<file_or_directory>
  • -m: Indicates the modification of ACL entries.

  • <permissions>: Specify the permissions you want to grant (e.g., rwx for read, write, and execute).

  • <user_or_group>: The user or group you want to assign the permissions to (e.g., john or developers).

  • <file_or_directory>: The target file or directory for which you want to set the ACL.

Example:

setfacl -m rwx:john:my_file.txt

This grants the user "john" read, write, and execute permissions on the file "my_file.txt."

getfacl: This command is used to view the Access Control Lists (ACL) of files and directories on Linux.

Syntax:getfacl

getfacl <file_or_directory>
  • <file_or_directory>: The file or directory for which you want to view the ACL.

Example:

getfacl my_file.txt

This displays the ACL entries for the file "my_file.txt," showing the user or group with specific permissions.

With these commands, you can wield the power of ACL on Linux and customize access rights with precision, making your system administration a breeze! πŸ˜„πŸ”’

Conclusion: You Hold the Linux Key πŸ”‘

And there you have it, dear Linux enthusiasts! File permissions are yet an essential aspect of ruling your digital kingdom. With the power of CHMOD, you hold the key to unlocking magical abilities and ensuring harmony in your Linux realm.

So go forth, experiment with permissions, and remember, even if you stumble upon permission pranks, it's all part of the fun and learning experience in this Linux circus! πŸŽͺ Embrace the quirks and keep your sense of humor intact!

May your Linux journey be filled with laughter, and may the file permissions be ever in your favor! πŸ˜„βœ¨

May the code be with you! πŸ€–πŸ’™

Β