<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammad Saimon</title>
    <description>The latest articles on DEV Community by Muhammad Saimon (@saimon23).</description>
    <link>https://dev.to/saimon23</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2007317%2Fe2d0f4c0-fb56-43d7-9349-da283a051374.jpg</url>
      <title>DEV Community: Muhammad Saimon</title>
      <link>https://dev.to/saimon23</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saimon23"/>
    <language>en</language>
    <item>
      <title>Linux File System and Permissions: A Detailed Guide</title>
      <dc:creator>Muhammad Saimon</dc:creator>
      <pubDate>Sat, 31 Aug 2024 13:43:31 +0000</pubDate>
      <link>https://dev.to/saimon23/linux-file-system-and-permissions-a-detailed-guide-58af</link>
      <guid>https://dev.to/saimon23/linux-file-system-and-permissions-a-detailed-guide-58af</guid>
      <description>&lt;p&gt;Welcome to the world of Linux, where everything is a file, and every file has a story to tell. Today, we're going to embark on a journey through the Linux file system and uncover the mysteries of file permissions. Whether you're a seasoned sysadmin or a curious newbie, this guide will help you understand the structure and security of your Linux environment with some catchy examples along the way. So, grab your favourite beverage, sit back, and let's get started!&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 1: The Linux File System Hierarchy
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Root of All Things: &lt;code&gt;'/'&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
In Linux, the file system begins at the root directory, represented by a simple &lt;code&gt;/&lt;/code&gt;. Think of this as the trunk of a massive tree, from which all other directories (branches) grow. Here are some of the key directories you'll find at the root level:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/bin&lt;/code&gt;&lt;/strong&gt;: This is where you'll find essential binary executables. For instance, commands like ls, cp, and mv live here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/boot&lt;/code&gt;&lt;/strong&gt;: Contains the files needed to boot your Linux system, including the kernel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/dev&lt;/code&gt;&lt;/strong&gt;: Short for devices, this directory holds files that represent hardware devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/etc&lt;/code&gt;&lt;/strong&gt;: The epicentre of configuration files and scripts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/home&lt;/code&gt;&lt;/strong&gt;: A personal haven for every user. Each user gets a subdirectory here, like /home/alice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/lib&lt;/code&gt;&lt;/strong&gt;: Shared libraries and kernel modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/mnt&lt;/code&gt;&lt;/strong&gt;: Temporary mount points for filesystems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/opt&lt;/code&gt;&lt;/strong&gt;: Optional software packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/proc&lt;/code&gt;&lt;/strong&gt;: A virtual filesystem that provides a mechanism to access kernel data structures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/root&lt;/code&gt;&lt;/strong&gt;: The home directory for the root user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/sbin&lt;/code&gt;&lt;/strong&gt;: System binaries, reserved for the system administrator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/tmp&lt;/code&gt;&lt;/strong&gt;: Temporary files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/usr&lt;/code&gt;&lt;/strong&gt;: User binaries and applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/var&lt;/code&gt;&lt;/strong&gt;: Variable data files like logs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Navigating the Tree&lt;/strong&gt;&lt;br&gt;
Imagine you're Hasan, a new user of a Linux system. You want to explore your home directory. Here's how you can do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /home/hasan
ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see all the files and subdirectories in your personal space. It's like opening the door to your digital room!&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 2: Understanding File Permissions
&lt;/h2&gt;

&lt;p&gt;Linux file permissions are crucial for system security and management. Here's a quick overview to help you understand how they work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8uf578k28s5213ilk8xs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8uf578k28s5213ilk8xs.png" alt="Image description" width="692" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Triad of Permissions&lt;/strong&gt;&lt;br&gt;
In Linux, every file and directory has a set of permissions that determines who can do what with them. These permissions are divided into three categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read (&lt;code&gt;r&lt;/code&gt;)&lt;/strong&gt;: Allows reading the contents of a file or listing the contents of a directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write (&lt;code&gt;w&lt;/code&gt;)&lt;/strong&gt;: Allows modifying a file or directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execute (&lt;code&gt;x&lt;/code&gt;)&lt;/strong&gt;: Allows executing a file (if it's a script or a program) or accessing a directory and its contents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Who Gets What?&lt;/strong&gt;&lt;br&gt;
Permissions are assigned to three types of users:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Owner&lt;/strong&gt;: The user who owns the file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Group&lt;/strong&gt;: A set of users who share the same permissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Others&lt;/strong&gt;: Everyone else.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Permission String&lt;/strong&gt;&lt;br&gt;
Permissions are represented as a string of ten characters, like this: &lt;br&gt;
&lt;code&gt;-rwxr-xr--&lt;/code&gt;. Let's break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first character indicates the type of file (&lt;code&gt;-&lt;/code&gt; for a regular file, &lt;code&gt;d&lt;/code&gt; for a directory).&lt;/li&gt;
&lt;li&gt;The next three characters (&lt;code&gt;rwx&lt;/code&gt;) are the owner's permissions.&lt;/li&gt;
&lt;li&gt;The following three (&lt;code&gt;r-x&lt;/code&gt;) are the group's permissions.&lt;/li&gt;
&lt;li&gt;The last three (&lt;code&gt;r--&lt;/code&gt;) are for others.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Decoding Permissions&lt;/strong&gt;&lt;br&gt;
Consider a &lt;em&gt;file&lt;/em&gt; with the following permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-rwxr-xr--
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The owner can read, write, and execute (&lt;code&gt;rwx&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The group can read and execute (&lt;code&gt;r-x&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Others can only read (&lt;code&gt;r--&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Changing Permissions: The '&lt;code&gt;chmod&lt;/code&gt;' Command&lt;/strong&gt;&lt;br&gt;
You can change file permissions using the &lt;code&gt;chmod&lt;/code&gt; command. There are &lt;em&gt;two ways&lt;/em&gt; to do this: &lt;code&gt;symbolic&lt;/code&gt; mode and &lt;code&gt;numeric&lt;/code&gt; mode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Symbolic Mode&lt;/strong&gt;&lt;br&gt;
In symbolic mode, you use letters to represent permissions and operators to add or remove them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User Types&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;u&lt;/code&gt;&lt;/strong&gt;: User (file owner)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;g&lt;/code&gt;&lt;/strong&gt;: Group (file's group)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;o&lt;/code&gt;&lt;/strong&gt;: Others (everyone else)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;a&lt;/code&gt;&lt;/strong&gt;: All (user, group, and others)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Operations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;+&lt;/code&gt;&lt;/strong&gt;: Add a permission&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-&lt;/code&gt;&lt;/strong&gt;: Remove a permission&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;=&lt;/code&gt;&lt;/strong&gt;: Set exact permissions, removing others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Permission Types&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;r&lt;/code&gt;&lt;/strong&gt;: Read&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;w&lt;/code&gt;&lt;/strong&gt;: Write&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;x&lt;/code&gt;&lt;/strong&gt;: Execute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Examples of Symbolic Mode&lt;/strong&gt;&lt;br&gt;
Add &lt;code&gt;execute&lt;/code&gt; permission for the &lt;code&gt;user&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod u+x file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove &lt;code&gt;write&lt;/code&gt; permission for the &lt;code&gt;group&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod g-w file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Setting &lt;code&gt;Exact (=)&lt;/code&gt; Permissions. Set &lt;code&gt;read&lt;/code&gt; and &lt;code&gt;write&lt;/code&gt; for the &lt;code&gt;user&lt;/code&gt;, &lt;code&gt;read&lt;/code&gt; for the &lt;code&gt;group&lt;/code&gt;, and no permissions for &lt;code&gt;others&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod u=rw,g=r,o= file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Combining Multiple Changes. Add &lt;code&gt;read&lt;/code&gt; permission for &lt;code&gt;group&lt;/code&gt; and &lt;code&gt;others&lt;/code&gt;, remove &lt;code&gt;execute&lt;/code&gt; for the &lt;code&gt;user&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod g+r,o+r,u-x file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Numeric Mode&lt;/strong&gt;&lt;br&gt;
In numeric mode, you use a three-digit number to set permissions. Each digit represents a set of permissions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read (&lt;code&gt;r&lt;/code&gt;) = 4&lt;/li&gt;
&lt;li&gt;Write (&lt;code&gt;w&lt;/code&gt;) = 2&lt;/li&gt;
&lt;li&gt;Execute (&lt;code&gt;x&lt;/code&gt;) = 1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Add these values to get the desired permissions. For example, &lt;code&gt;755&lt;/code&gt; means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Owner: &lt;code&gt;rwx&lt;/code&gt; (4+2+1 = 7)&lt;/li&gt;
&lt;li&gt;Group: &lt;code&gt;r-x&lt;/code&gt; (4+0+1 = 5)&lt;/li&gt;
&lt;li&gt;Others: &lt;code&gt;r-x&lt;/code&gt; (4+0+1 = 5)
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 755 file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Example: Setting Permissions&lt;/strong&gt;&lt;br&gt;
Imagine you have a script &lt;code&gt;run.sh&lt;/code&gt; that you want to make executable by everyone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 755 run.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now everyone can run the script, but only you can modify it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 3: Ownership and Groups
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42fmc4o14l476ix0kldx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42fmc4o14l476ix0kldx.png" alt="Image description" width="650" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The '&lt;code&gt;chown&lt;/code&gt;' Command&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;chown&lt;/code&gt; command changes the owner of a file. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chown hasan file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes Hasan the owner of &lt;code&gt;file.txt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The '&lt;code&gt;chgrp&lt;/code&gt;' Command&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;chgrp&lt;/code&gt; command changes the group of a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chgrp staff file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This assigns the file to the &lt;code&gt;staff&lt;/code&gt; group.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: Changing Ownership and Group
&lt;/h2&gt;

&lt;p&gt;Suppose Mishu wants to transfer ownership of &lt;code&gt;project.zip&lt;/code&gt; to &lt;em&gt;Hasan&lt;/em&gt; and change its group to &lt;code&gt;developers&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chown hasan project.zip
chgrp developers project.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Hasan owns &lt;code&gt;project.zip&lt;/code&gt;, and it's part of the &lt;code&gt;developers&lt;/code&gt; group.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 4: Fun with Permissions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Making a Secret Directory&lt;/strong&gt;&lt;br&gt;
Let's say you want to create a secret directory that only you can access. Here's how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir secret
chmod 700 secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;700&lt;/code&gt; means only the owner can read, write, and execute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Creating a Shared Directory&lt;/strong&gt;&lt;br&gt;
Suppose you're working on a group project and need a shared directory where everyone can add and edit files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir shared
chmod 770 shared
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;770&lt;/code&gt; means the owner and group can read, write, and execute, but others have no access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Permission Pitfalls&lt;/strong&gt;&lt;br&gt;
Imagine you accidentally made a sensitive file readable by everyone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 644 sensitive.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;644&lt;/code&gt; means the owner can read and write, but everyone else can read.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To fix this, you need to restrict access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 600 sensitive.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;600&lt;/code&gt; means only the owner can read and write.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And there you have it - a comprehensive, fun-filled guide to the Linux file system and permissions. By now, you should feel more confident navigating directories and managing file permissions like a pro. Understanding and managing file permissions is vital for maintaining system security and ensuring proper access control. Make sure you regularly check and update permissions to keep your Linux environment secure.&lt;/p&gt;

&lt;p&gt;Stay tuned for more exciting Linux adventures, and until next time, happy computing!&lt;/p&gt;

&lt;p&gt;Stay classy! 😎&lt;/p&gt;

</description>
      <category>linux</category>
      <category>filepermission</category>
      <category>linuxfilepermission</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
