<?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: Nedim Hadzimahmutovic</title>
    <description>The latest articles on DEV Community by Nedim Hadzimahmutovic (@nedtechie).</description>
    <link>https://dev.to/nedtechie</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%2F42380%2F52eeb0e4-6881-4867-9fe9-9301cbf99564.jpeg</url>
      <title>DEV Community: Nedim Hadzimahmutovic</title>
      <link>https://dev.to/nedtechie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nedtechie"/>
    <language>en</language>
    <item>
      <title>FREE EBOOK: Master Linux File Permissions 🐧</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Thu, 23 Oct 2025 05:13:14 +0000</pubDate>
      <link>https://dev.to/nedtechie/free-ebook-master-linux-file-permissions-4n50</link>
      <guid>https://dev.to/nedtechie/free-ebook-master-linux-file-permissions-4n50</guid>
      <description>&lt;p&gt;Updated my book with extra diagrams and examples in this second revision! Because I love this community, I'm giving the updated version away for free! &lt;a href="https://nedtechie.gumroad.com/l/Master_Linux_Permissions_While_Your_Coffee_Brews" rel="noopener noreferrer"&gt;Go get it!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>books</category>
      <category>resources</category>
      <category>linux</category>
      <category>security</category>
    </item>
    <item>
      <title>Master Special Permissions in Linux While Your Coffee Brews</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Fri, 31 Jan 2025 04:28:01 +0000</pubDate>
      <link>https://dev.to/nedtechie/master-special-permissions-in-linux-while-your-coffee-brews-4ea9</link>
      <guid>https://dev.to/nedtechie/master-special-permissions-in-linux-while-your-coffee-brews-4ea9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is the &lt;strong&gt;&lt;em&gt;fourth&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;last&lt;/em&gt;&lt;/strong&gt; article from a series compiled from my notes while taking the &lt;strong&gt;LPI&lt;/strong&gt; exams.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The three special permissions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The &lt;em&gt;&lt;code&gt;Sticky&lt;/code&gt; bit&lt;/em&gt;,&lt;/li&gt;
&lt;li&gt;  the &lt;em&gt;&lt;code&gt;SUID&lt;/code&gt; bit&lt;/em&gt;, and&lt;/li&gt;
&lt;li&gt;  the &lt;em&gt;&lt;code&gt;SGID&lt;/code&gt; bit&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These permissions can be specified using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;symbolic mode:&lt;/strong&gt; they are represented by letters (&lt;strong&gt;t&lt;/strong&gt;, &lt;strong&gt;s&lt;/strong&gt;,
&lt;strong&gt;S&lt;/strong&gt;), or&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;numeric mode:&lt;/strong&gt; they are represented by numbers (&lt;strong&gt;1&lt;/strong&gt;, &lt;strong&gt;2&lt;/strong&gt;,
&lt;strong&gt;4&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Sticky Bit
&lt;/h3&gt;

&lt;p&gt;The sticky bit is also known as the restricted deletion flag. It does not affect individual files, but when set at the directory level it prevents users from removing or renaming files. Only the &lt;strong&gt;owner&lt;/strong&gt; and the &lt;strong&gt;root&lt;/strong&gt; user can remove files in that directory.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The sticky bit on &lt;strong&gt;files&lt;/strong&gt; is &lt;strong&gt;ignored&lt;/strong&gt; on the modern versions of Linux.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Identifying the Sticky Bit
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6idll6ri0gm2ruqqf5zo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6idll6ri0gm2ruqqf5zo.png" alt="Identifying the Sticky Bit" width="473" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example: the &lt;code&gt;/tmp&lt;/code&gt; directory.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A well-known system directory with the sticky bit set on it is the&lt;br&gt;
&lt;code&gt;/tmp&lt;/code&gt; directory as shown below. Since this directory is word-readable and world-writable it prevents users from deleting files unless they own the parent directory.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; /tmp
drwxrwxrwt 35 root root 4096 Dec 25 19:09 /tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice the &lt;strong&gt;&lt;code&gt;t&lt;/code&gt;&lt;/strong&gt; at the last place in the permissions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Setting the Sticky Bit
&lt;/h4&gt;

&lt;h6&gt;
  
  
  Symbolic mode
&lt;/h6&gt;

&lt;p&gt;In symbolic mode, the sticky bit is represented by a &lt;code&gt;"t"&lt;/code&gt; within the other's permissions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  To &lt;em&gt;enable&lt;/em&gt; it, use &lt;strong&gt;"&lt;code&gt;+t&lt;/code&gt;"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  To &lt;em&gt;disable&lt;/em&gt; it, use &lt;strong&gt;"&lt;code&gt;-t&lt;/code&gt;"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;For example set the sticky bit for &lt;code&gt;mytmp&lt;/code&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +t mytmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check the directory permissions use the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; ./mytmp
drwxrwxrwt 2 root root 4096 Dec 25 19:37 ./mytmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  Numeric Mode
&lt;/h6&gt;

&lt;p&gt;In numeric mode, we will use the four-digit notation and set the first digit to "&lt;code&gt;1&lt;/code&gt;" which sets the sticky bit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example where the execute permission is set.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;1771 mytmp
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; ./mytmp
drwxrwx--t 2 root root 4096 Dec 25 19:37 ./mytmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example where the execute permission is set.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;1777 mytmp
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; ./mytmp
drwxrwxrwt 2 root root 4096 Dec 25 19:37 ./mytmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example where the execute permission is &lt;code&gt;NOT&lt;/code&gt; set.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;1774 mytmp
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; ./mytmp
drwxrwxr-T 2 root root 4096 Dec 25 19:37 ./mytmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example where the execute permission is &lt;code&gt;NOT&lt;/code&gt; set.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;1770 mytmp
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; ./mytmp
drwxrwx--T 2 root root 4096 Dec 25 19:37 ./mytmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The sticky bit is represented with &lt;strong&gt;&lt;code&gt;t&lt;/code&gt;&lt;/strong&gt; when the execution permission&lt;br&gt;
is enabled, and as &lt;strong&gt;&lt;code&gt;T&lt;/code&gt;&lt;/strong&gt; when the execute permission is missing.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;/tmp&lt;/code&gt; and &lt;code&gt;/var/tmp&lt;/code&gt; directories often have the sticky bit set to prevent unauthorized users from deleting or modifying files created by other users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  SUID
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;SUID&lt;/code&gt; (Set User ID) is a special permission that allows a file to be executed with the privileges of the user who owns the file. When a &lt;strong&gt;SUID&lt;/strong&gt; is set on a file where the owner is root then the user that is running the file can execute that file with &lt;em&gt;root&lt;/em&gt; privileges. This means that the user running the program will temporarily inherit the root permissions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Identifying &lt;code&gt;SUID&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Files with &lt;code&gt;SUID&lt;/code&gt; bit show a letter &lt;strong&gt;'s'&lt;/strong&gt; replacing the &lt;strong&gt;'x'&lt;/strong&gt; on the user permissions filed, as shown in the following diagram and examples.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xv7zew661c7keopvg5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xv7zew661c7keopvg5e.png" alt="SUID" width="464" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SUID can only be set on files, not directories.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example: the &lt;code&gt;password&lt;/code&gt; command.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;em&gt;We will check the file permissions using the &lt;code&gt;ls&lt;/code&gt; command.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /usr/bin/passwd
&lt;span class="nt"&gt;-rwsr-xr-x&lt;/span&gt; 1 root root 64152 May 30  2024 /usr/bin/passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;em&gt;Next, we check the permissions with &lt;code&gt;stat&lt;/code&gt; to show the&lt;br&gt;
permissions in octal and human-readable formats.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"File %n has %a and %A permissions"&lt;/span&gt; /usr/bin/passwd
File /usr/bin/passwd has 4755 and &lt;span class="nt"&gt;-rwsr-xr-x&lt;/span&gt; permissions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice the &lt;strong&gt;s&lt;/strong&gt; in the user ownership field in the permissions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Setting &lt;code&gt;SUID&lt;/code&gt;
&lt;/h4&gt;

&lt;h6&gt;
  
  
  Symbolic Mode
&lt;/h6&gt;

&lt;p&gt;In symbolic mode, &lt;strong&gt;SUID&lt;/strong&gt; is set by using the letter "&lt;code&gt;s&lt;/code&gt;" in the user permission field.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  To enable it, use &lt;strong&gt;"&lt;code&gt;u+s&lt;/code&gt;"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  To disable it, use &lt;strong&gt;"&lt;code&gt;u-s&lt;/code&gt;"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Examples where we add only the SUID without any other user permissions.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;u+s myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;---S------&lt;/span&gt; 1 root root 0 Oct 24 13:05 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;u+s,u-rwx myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;---S------&lt;/span&gt; 1 root root 0 Dec 30 17:46 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please notice the capital letter &lt;strong&gt;S&lt;/strong&gt;. That means the execute user&lt;br&gt;
permissions are missing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this example where we add the SUID bit, read, write, and execute user permissions.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;u+rwxs myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rws------&lt;/span&gt; 1 root root 0 Oct 24 13:05 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If the user permission section shows &lt;strong&gt;"&lt;code&gt;s&lt;/code&gt;"&lt;/strong&gt; instead of &lt;strong&gt;"&lt;code&gt;x&lt;/code&gt;"&lt;/strong&gt;, then the &lt;em&gt;&lt;code&gt;SUID&lt;/code&gt;&lt;/em&gt; bit is set.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h6&gt;
  
  
  Numeric Mode
&lt;/h6&gt;

&lt;p&gt;The octal value of &lt;code&gt;SUID&lt;/code&gt; is &lt;strong&gt;&lt;code&gt;4&lt;/code&gt;&lt;/strong&gt;, therefore we add &lt;strong&gt;&lt;code&gt;4&lt;/code&gt;&lt;/strong&gt; to the user permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here is an example where we set the SUID only, without any other user permissions.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;4000 myfile
root@nedim-IdeaPad-box:~/emptydir# &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;---S------&lt;/span&gt; 1 root root 0 Oct 24 13:05 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this example, we set SUID and grant 755 permissions.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;4755 myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rwsr-xr-x&lt;/span&gt; 1 root root 0 Oct 24 13:05 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  SGID
&lt;/h3&gt;

&lt;p&gt;Set GID, also known as &lt;code&gt;SGID&lt;/code&gt; or Set Group ID bit, is a permission that can be applied to both executable files and directories.&lt;/p&gt;

&lt;p&gt;This special permission has the following functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  When applied to executable files, once a user executes the file it grants the resulting process permissions of the group that owns the file.&lt;/li&gt;
&lt;li&gt;  When applied to directories, it makes every file or directory
created under it inherit the group from the parent directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;As we explained previously, when the &lt;code&gt;SGID&lt;/code&gt; bit is set on a folder, any new files created inside that folder will automatically belong to the same group as the folder itself. It doesn't matter who created the file.&lt;br&gt;
This can be helpful when you want all files in a folder to belong to a specific group, even if different people create those files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Identifying &lt;code&gt;SGID&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Files with &lt;code&gt;SGID&lt;/code&gt; bit show a letter &lt;strong&gt;"&lt;code&gt;s&lt;/code&gt;"&lt;/strong&gt; replacing the &lt;strong&gt;"x"&lt;/strong&gt; on the group permissions. Please see the following diagram and examples.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsxwnrxg2nkx050rpc277.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsxwnrxg2nkx050rpc277.png" alt="SGID" width="463" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Setting &lt;code&gt;SGID&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;You need to be careful when using the &lt;code&gt;SGID&lt;/code&gt; bit because it can create security problems. For example, if a folder with the &lt;code&gt;SGID&lt;/code&gt; bit is set it can be written to by anyone who is a member of that group. Anyone in that group could create files within that folder. These files would belong to the group, which could give them access to data they shouldn't&lt;br&gt;
have.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's usually better to use group ownership and permissions correctly instead of relying on the &lt;code&gt;SGID&lt;/code&gt; bit.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5&gt;
  
  
  Symbolic Mode
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;To set the &lt;code&gt;SGID&lt;/code&gt; bit on a directory, in &lt;code&gt;symbolic&lt;/code&gt; mode, we use the command demonstrated below.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;g+s mydirectory
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; mydirectory
drwxr-sr-x 2 root root 4096 Dec 30 19:47 mydirectory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To set the &lt;code&gt;SGID&lt;/code&gt; bit on a &lt;code&gt;file&lt;/code&gt; in symbolic mode, we use the command demonstrated below.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;g+s,g+rwx myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;----rws---&lt;/span&gt; 1 root root 0 Dec 30 17:46 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To set the &lt;code&gt;SGID&lt;/code&gt; bit on a &lt;code&gt;file&lt;/code&gt; in symbolic mode, with missing execute permissions, we use the command demonstrated below.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;g+s,g+rw,g-x myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;----rwS---&lt;/span&gt; 1 root root 0 Dec 30 17:46 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please notice the capital letter &lt;strong&gt;S&lt;/strong&gt;. That means the execute group permissions are missing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  Numeric Mode
&lt;/h5&gt;

&lt;p&gt;The octal value of &lt;code&gt;SGID&lt;/code&gt; is &lt;strong&gt;&lt;code&gt;2&lt;/code&gt;&lt;/strong&gt;, therefore we add &lt;code&gt;2&lt;/code&gt; to the group permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;To set the &lt;code&gt;SGID&lt;/code&gt; bit on a &lt;code&gt;directory&lt;/code&gt;, in numeric mode, we use the command demonstrated below.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;2755 mydirectory
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; mydirectory
drwxr-sr-x 2 root root 4096 Dec 30 19:47 mydirectory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To set the &lt;code&gt;SGID&lt;/code&gt; bit on a &lt;code&gt;file&lt;/code&gt;, in numeric mode, we use the command demonstrated below.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;2755 myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rwxr-sr-x&lt;/span&gt; 1 root root 0 Dec 30 17:46 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Special Directories
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Understanding Temporary Files
&lt;/h3&gt;

&lt;p&gt;Temporary files are files used by programs for short-term data storage. They can be used for various purposes, such as storing process data and logs. The &lt;em&gt;Filesystem Hierarchy Standard (FHS)&lt;/em&gt; defines standard locations for temporary files, as shown in the table below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9747odvxcojf0we1sep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9747odvxcojf0we1sep.png" alt="Temporary files locations" width="800" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Both &lt;code&gt;/tmp&lt;/code&gt; and &lt;code&gt;/var/tmp&lt;/code&gt; are used for temporary files but have different behaviors.&lt;/li&gt;
&lt;li&gt;  Files in &lt;code&gt;/tmp&lt;/code&gt; are typically erased during system boot-up, while files in &lt;code&gt;/var/tmp&lt;/code&gt; are usually preserved between reboots.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;/run&lt;/code&gt; directory is used for run-time variable data used by
running processes, such as process identifier files (PID). It is intended to be cleared during system boot-up.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Securing Temporary Files
&lt;/h3&gt;

&lt;p&gt;The most widely used location for storing temp files is the &lt;code&gt;/tmp&lt;/code&gt;&lt;br&gt;
directory. It is a system-wide temporary directory that any user can write and read from. Managing permissions for this directory is a challenge as the correct access permissions need to be set to make sure that users cannot erase or modify files created by others. In short, choosing &lt;code&gt;/tmp&lt;/code&gt; to store and execute your files can be very dangerous.&lt;/p&gt;

&lt;p&gt;To implement security to the &lt;code&gt;/tmp&lt;/code&gt; directory, the &lt;strong&gt;sticky bit&lt;/strong&gt; is used. When set for a directory, the sticky bit prevents users from removing or renaming a file within that directory unless they own the file.&lt;/p&gt;
&lt;h4&gt;
  
  
  Identifying the Sticky bit on &lt;code&gt;/tmp&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;To check the permissions on &lt;code&gt;/tmp&lt;/code&gt; use the &lt;code&gt;ls&lt;/code&gt; command, as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ldh&lt;/span&gt; /tmp/ /var/tmp/
drwxrwxrwt 392 root root  28K Dec  2 08:42 /tmp/
drwxrwxrwt  14 root root 4.0K Dec  2 08:39 /var/tmp/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The sticky bit is indicated by a "&lt;code&gt;t&lt;/code&gt;" replacing the "&lt;code&gt;x&lt;/code&gt;" in the&lt;br&gt;
permission for others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgnphpvkpj7vz8vf0z1qh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgnphpvkpj7vz8vf0z1qh.png" alt="Identifying the Sticky bit on /tmp" width="542" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The sticky bit helps to protect files created by other users from being accidentally or maliciously deleted or modified.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In Linux, everything you interact with, such as files, folders, and even devices like your keyboard or mouse, is considered a &lt;code&gt;file&lt;/code&gt;. This might seem unusual the first time you start working on Linux, but it's a core concept that makes Linux incredibly flexible and powerful.&lt;/p&gt;

&lt;p&gt;In this article series, we learned about the different types of files, from regular files to special files that represent hardware or are used for communication. We also learned about links, which are shortcuts to files, and how to identify them.&lt;/p&gt;

&lt;p&gt;One of the most important aspects of Linux is security. File permissions determine who can access and modify your files. This is crucial in a multi-user environment, where you usually share a computer with other people. We learned how to use commands like &lt;code&gt;ls&lt;/code&gt; and &lt;code&gt;chmod&lt;/code&gt; to view and change these permissions, giving you control over your data.&lt;/p&gt;

&lt;p&gt;Special permissions, like the &lt;code&gt;Sticky bit&lt;/code&gt;, &lt;code&gt;SUID&lt;/code&gt;, and &lt;code&gt;SGID&lt;/code&gt;, provide extra layers of security. For example, the &lt;code&gt;Sticky bit&lt;/code&gt; can prevent other users from deleting files in shared directories.&lt;/p&gt;

&lt;p&gt;Understanding file types and permissions is a must for any Linux user. It allows you to manage your system efficiently and protect your data.&lt;/p&gt;

&lt;p&gt;I hope the effort I put into this book, especially the graphics makes this topic as simplified as possible. Let me know if you'd like any specific parts explained further.&lt;/p&gt;




&lt;p&gt;Please do not hesitate to contact me, via the links below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/neidiom" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Linkedin&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nedtechie.gumroad.com" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Gumroad&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://x.com/ned_techie" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;X&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;This article is part of my book: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://nedtechie.gumroad.com/l/Master_Linux_Permissions_While_Your_Coffee_Brews" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bca5kibedyv9dr210fh.jpg" title="Master Linux Permissions and File Types While Your Coffee Brews" alt="Master Linux Permissions and File Types While Your Coffee Brews" width="224" height="336"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>linux</category>
      <category>devops</category>
      <category>security</category>
      <category>lpi</category>
    </item>
    <item>
      <title>Master Linux File Ownership While Your Coffee Brews</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Sun, 19 Jan 2025 13:52:11 +0000</pubDate>
      <link>https://dev.to/nedtechie/master-linux-file-ownership-while-your-coffee-brews-3lg8</link>
      <guid>https://dev.to/nedtechie/master-linux-file-ownership-while-your-coffee-brews-3lg8</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is the &lt;strong&gt;third article&lt;/strong&gt; from a series compiled from my notes while taking the &lt;strong&gt;LPI&lt;/strong&gt; exams.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;File ownership is a very important security aspect of the Linux operating system. The &lt;code&gt;chown&lt;/code&gt; command lets you change who owns a file or folder. This is very helpful when administrators need to give or take away access to certain files. This chapter introduces how to use the chown command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify File Ownership
&lt;/h2&gt;

&lt;p&gt;To view the file ownership for &lt;code&gt;/etc/passwd&lt;/code&gt; do as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /etc/passwd
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 root root 3274 Dec 22 16:13 /etc/passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmdf0xy03z1z41c2nn56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmdf0xy03z1z41c2nn56.png" alt="Identify File Ownership" width="800" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;strong&gt;&lt;code&gt;chown&lt;/code&gt;&lt;/strong&gt; command
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;chown&lt;/code&gt; command is used to modify file ownership. The syntax for the &lt;code&gt;chown&lt;/code&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chown &lt;/span&gt;user_name:group_name file_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view the current ownership of a file use the &lt;code&gt;ls -l&lt;/code&gt; command to list files with detailed information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; target_file.txt
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 root root 0 Nov  6 12:23 target_file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change the Owner
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Following is an example of how to change the owner of a file.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;First, we create the &lt;code&gt;myfile&lt;/code&gt; file and list the current ownership details.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 root root 0 Jan  1 22:36 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;The next step is to change the owner from root to user &lt;code&gt;kulin&lt;/code&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chown&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; kulin myfile
changed ownership of &lt;span class="s1"&gt;'myfile'&lt;/span&gt; from root to kulin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;The last step is to list the new ownership information.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 kulin root 0 Jan  1 22:36 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To view only the username of the owner you can use the &lt;code&gt;stat&lt;/code&gt; command as follows.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"The username %U is the owner for the file %n"&lt;/span&gt; myfile
The username kulin is the owner &lt;span class="k"&gt;for &lt;/span&gt;the file myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change the Owner Group
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Following is an example of how to change the group ownership of a file.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;First we list the current ownership information.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 kulin root 0 Jan  1 22:36 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Next, we change the group of the owner.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chown&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; :kulin myfile
changed ownership of &lt;span class="s1"&gt;'myfile'&lt;/span&gt; from kulin:root to :kulin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;The last step is to list the new ownership information.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; myfile
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 kulin kulin 0 Jan  1 22:36 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To view the only group of the owner you can use the &lt;code&gt;stat&lt;/code&gt; command as follows.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"The group name of the owner is %G for the file %n"&lt;/span&gt; myfile
The group name of the owner is kulin &lt;span class="k"&gt;for &lt;/span&gt;the file myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To change both user and group at the same time follow the next example.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chown&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; kulin:kulin myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;To change the ownership of a directory and all its contents recursively, use the &lt;code&gt;-R&lt;/code&gt; option as demonstrated in the next example.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; username:groupname directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check out the man pages for more info.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;chown&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;This article is part of my book: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://nedtechie.gumroad.com/l/Master_Linux_Permissions_While_Your_Coffee_Brews" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bca5kibedyv9dr210fh.jpg" title="Master Linux Permissions and File Types While Your Coffee Brews" alt="Master Linux Permissions and File Types While Your Coffee Brews" width="224" height="336"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>linux</category>
      <category>devops</category>
      <category>lpi</category>
      <category>security</category>
    </item>
    <item>
      <title>Master Linux File Permissions While Your Coffee Brews</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Sat, 18 Jan 2025 04:24:52 +0000</pubDate>
      <link>https://dev.to/nedtechie/master-linux-file-permissions-while-your-coffee-brews-2keh</link>
      <guid>https://dev.to/nedtechie/master-linux-file-permissions-while-your-coffee-brews-2keh</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is the &lt;strong&gt;&lt;em&gt;second article&lt;/em&gt;&lt;/strong&gt; from a series compiled from my notes while taking the &lt;strong&gt;LPI&lt;/strong&gt; exams.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Linux allows multiple users to access and use the system simultaneously. File permissions are crucial in a multi-user system to protect user privacy. It ensures that only authorized users can access and modify files.&lt;/p&gt;

&lt;p&gt;The three sets of permissions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Owner permissions&lt;/strong&gt;: Apply to the user who owns the file.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Group permissions&lt;/strong&gt;: Apply to group members that own the
file.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Other permissions&lt;/strong&gt;: Apply to all other users who are not the
owner or a member of the group.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;ls&lt;/code&gt; command
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;ls&lt;/code&gt; by default is used to list the contents of a directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example to display contents of the current directory&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, it can list file permissions and ownerships or find hidden files and directories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example to check the permissions of files&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can use the &lt;code&gt;-l&lt;/code&gt; option which is known as &lt;code&gt;long listing format&lt;/code&gt;. The complete command would be &lt;code&gt;ls -l&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;

total 552
&lt;span class="nt"&gt;-rw-rw-r--&lt;/span&gt; 1 coolin coolin 493743 Oct 23 10:58 book.pdf
drwxrwxr-x 5 coolin coolin   4096 Oct 15 08:27 chapters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Infographics that explain each column in a long listing representation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example the following case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;drwxrwxr-x 5 coolin coolin   4096 Oct 15 08:27 chapters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Access the man page for more info.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hidden Files
&lt;/h2&gt;

&lt;p&gt;To view hidden files in a directory use the &lt;code&gt;-a&lt;/code&gt; or &lt;code&gt;--all&lt;/code&gt; option with the &lt;code&gt;ls&lt;/code&gt; command. This option tells &lt;code&gt;ls&lt;/code&gt; to list all files, including those that are hidden.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;An example can be found below&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; ~
&lt;span class="nb"&gt;.&lt;/span&gt;  ..  .bash_history  .bashrc  .profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; ~
total 76
drwx------  8 root root  4096 Oct 23 14:47 &lt;span class="nb"&gt;.&lt;/span&gt;
drwxr-xr-x 23 root root  4096 Aug  5 17:07 ..
&lt;span class="nt"&gt;-rw-------&lt;/span&gt;  1 root root 24062 Oct 22 21:20 .bash_history
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;  1 root root   161 Apr 22  2024 .profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refer to the &lt;code&gt;ls&lt;/code&gt; command's manual pages for more details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Directory Permissions
&lt;/h2&gt;

&lt;p&gt;Directories are file types that are marked with the letter &lt;strong&gt;&lt;code&gt;d&lt;/code&gt;&lt;/strong&gt;. You set the permissions the same way as with files, but directories behave differently than files when it comes to permissions.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  The Read Permission
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Allows a user to view the contents of a directory, such as listing files and subdirectories.&lt;/li&gt;
&lt;li&gt;  A user with 'r' permission can not read the contents of individual files within a directory.&lt;/li&gt;
&lt;li&gt;  The 'r' permission only grants access to the directory's contents, not the individual files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Write Permission
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Allows a user to modify the contents of a directory, including
creating, deleting, and renaming files.&lt;/li&gt;
&lt;li&gt;  A user with 'w' permission can change the permissions of any file
within a directory, regardless of their permissions or ownership.&lt;/li&gt;
&lt;li&gt;  The 'w' permission grants the ability to change file permissions
within the directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Execute Permission
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Allows a user to enter or access a directory.&lt;/li&gt;
&lt;li&gt;  The 'x' permission does not grant access to listing the contents of
a directory.&lt;/li&gt;
&lt;li&gt;  The 'x' permission only allows entry into the directory. To list the
contents, the 'r' permission is also required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To remove all permissions use the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;0000 myfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  File Permissions
&lt;/h2&gt;

&lt;p&gt;To understand security, you need to master Linux file permissions. As&lt;br&gt;
they control who can access files, and modify them it is crucial to&lt;br&gt;
understand how they work and how to correctly set file permissions.&lt;/p&gt;

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

&lt;p&gt;A dash (&lt;code&gt;-&lt;/code&gt;) represents the lack of a particular permission.&lt;/p&gt;
&lt;h2&gt;
  
  
  The &lt;code&gt;chmod&lt;/code&gt; command
&lt;/h2&gt;

&lt;p&gt;Using the &lt;code&gt;chmod&lt;/code&gt; command you &lt;strong&gt;change file mode bits&lt;/strong&gt; meaning you can&lt;br&gt;
modify file permissions.&lt;/p&gt;

&lt;p&gt;There are two modes to change permissions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Symbolic mode&lt;/strong&gt;,&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Numeric mode&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Symbolic Mode
&lt;/h3&gt;

&lt;p&gt;In this mode, permissions are represented by letters. The symbolic mode&lt;br&gt;
offers a detailed approach to modifying permissions, allowing you to add&lt;br&gt;
or remove specific permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this example we will make a file readable and executable by everyone, you would use the following example&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;a+rx file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;This is an example of how you use the symbolic mode to add read and write permissions for the user and group, but revoke all permissions for others&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;ug+rw-x,o-rwx text.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check if permissions were set correctly use the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt; text.txt
&lt;span class="nt"&gt;-rw-rw----&lt;/span&gt; 1 kulin kulin 0 Dec 24 20:16 text.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Numeric Mode
&lt;/h3&gt;

&lt;p&gt;In this mode, permissions are represented using numbers. In this mode&lt;br&gt;
permissions are represented as follows: &lt;strong&gt;read is &lt;code&gt;4&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;write is&lt;br&gt;
&lt;code&gt;2&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;execute is &lt;code&gt;1&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Overview of Permissions
&lt;/h4&gt;

&lt;p&gt;A basic permissions demonstration can be found in the next table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feu67qe9y4inz0zq18gwh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feu67qe9y4inz0zq18gwh.png" alt="Image description" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Detailed Overview of Permissions
&lt;/h4&gt;

&lt;p&gt;A demonstration of detailed permissions can be found in the next table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0cxifttrbuaduw1g2ieu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0cxifttrbuaduw1g2ieu.png" alt="Image description" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Commonly Used Permissions
&lt;/h3&gt;

&lt;p&gt;A common practice when setting permissions to files and directories is&lt;br&gt;
as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Directories: &lt;strong&gt;755&lt;/strong&gt; or &lt;strong&gt;750&lt;/strong&gt;,&lt;/li&gt;
&lt;li&gt;  Files: &lt;strong&gt;644&lt;/strong&gt; or &lt;strong&gt;640&lt;/strong&gt;,&lt;/li&gt;
&lt;li&gt;  Sensitive files containing credentials: &lt;strong&gt;600&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;-&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;Warning&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;The 777 is a world-readable type of permission meaning everyone gets all permissions. It should be used with extreme caution.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Refer to the &lt;code&gt;chmod&lt;/code&gt; command's manual pages for more details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;chmod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The &lt;code&gt;stat&lt;/code&gt; command
&lt;/h2&gt;

&lt;p&gt;This command is used to status files. We will cover the basic use cases&lt;br&gt;
that are useful in the context of this chapter.&lt;/p&gt;
&lt;h3&gt;
  
  
  Display Permissions in Octal Mode
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example to easily get a file's permissions in octal mode&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %a /etc/passwd
644
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Display Permissions in Human Readable Form
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example to easily get a file's permissions in human-readable form&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %A /etc/passwd
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;You can combine &lt;code&gt;stat&lt;/code&gt; options as shown below.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"%n is a %F, permissions are %A, in octal %a"&lt;/span&gt; /etc/passwd
/etc/passwd is a regular file, permissions are &lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;, &lt;span class="k"&gt;in &lt;/span&gt;octal 644
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refer to the &lt;code&gt;stat&lt;/code&gt; command's manual pages for more details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;stat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;This article is part of my book: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://nedtechie.gumroad.com/l/Master_Linux_Permissions_While_Your_Coffee_Brews" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bca5kibedyv9dr210fh.jpg" title="Master Linux Permissions and File Types While Your Coffee Brews" alt="Master Linux Permissions and File Types While Your Coffee Brews" width="224" height="336"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>linux</category>
      <category>devops</category>
      <category>lpi</category>
      <category>security</category>
    </item>
    <item>
      <title>Master Linux File Types While Your Coffee Brews</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Thu, 16 Jan 2025 07:42:16 +0000</pubDate>
      <link>https://dev.to/nedtechie/master-linux-file-types-while-your-coffee-brews-3d35</link>
      <guid>https://dev.to/nedtechie/master-linux-file-types-while-your-coffee-brews-3d35</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is the &lt;strong&gt;&lt;em&gt;first article&lt;/em&gt;&lt;/strong&gt; from a series compiled from my notes while taking the &lt;strong&gt;LPI&lt;/strong&gt; exams.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A well-known expression says that everything in Linux is considered a file. In the following diagram, you can find a map that shows the most common file types.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Common File Types
&lt;/h2&gt;

&lt;p&gt;The three most common file types are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Regular files&lt;/strong&gt;: A Regular file can contain any data and can be
modified, moved, copied, or deleted.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Directories&lt;/strong&gt;: A directory is a special file containing other
files or directories, helping to organize the file system.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Links&lt;/strong&gt;: A link is a pointer to &lt;strong&gt;another file&lt;/strong&gt; or &lt;strong&gt;directory&lt;/strong&gt;
elsewhere in the same file system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Less Common File Types
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Block devices&lt;/strong&gt;: A block device represents a virtual or physical
device, typically a disk or other storage device.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Character devices&lt;/strong&gt;: A character device represents a virtual or
physical device, such as terminals or serial ports.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Sockets&lt;/strong&gt;: A socket is a channel for communication between
two programs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Identify File Types
&lt;/h2&gt;

&lt;p&gt;The easiest way to identify a file's type is to use the &lt;code&gt;ls&lt;/code&gt; command,&lt;br&gt;
using the long listing format.&lt;/p&gt;

&lt;p&gt;Refer to the following table for more information.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File Type&lt;/th&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Permissions&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Regular File&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;-&lt;/strong&gt;rw-------&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Directory&lt;/td&gt;
&lt;td&gt;d&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;d&lt;/strong&gt;rwxr-xr-x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Symbolic Link&lt;/td&gt;
&lt;td&gt;l&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;l&lt;/strong&gt;rwxrwxrwx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Block Device&lt;/td&gt;
&lt;td&gt;b&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;b&lt;/strong&gt;rw-rw----&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Character Device&lt;/td&gt;
&lt;td&gt;c&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;c&lt;/strong&gt;rw-rw----&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Socket&lt;/td&gt;
&lt;td&gt;s&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;s&lt;/strong&gt;rw-rw----&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example of using the &lt;code&gt;stat&lt;/code&gt; command to identify the file type.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"%n is a %F"&lt;/span&gt; /etc/passwd
/etc/passwd is a regular file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Identify Regular Files
&lt;/h3&gt;

&lt;p&gt;Regular files are marked with the &lt;strong&gt;&lt;code&gt;-&lt;/code&gt;&lt;/strong&gt; symbol.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This is an example of using &lt;code&gt;ls&lt;/code&gt; to identify a regular file, is where the first letter in the output of &lt;code&gt;ls -l&lt;/code&gt; represents the file type.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /etc/passwd
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 root root 3274 Dec 22 16:13 /etc/passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Identify Directories
&lt;/h3&gt;

&lt;p&gt;Directories are marked with the &lt;strong&gt;&lt;code&gt;d&lt;/code&gt;&lt;/strong&gt; letter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example of using &lt;code&gt;ls&lt;/code&gt; to identify directories.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; /etc/
drwxr-xr-x 168 root root 12288 Jan  1 15:12 /etc/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Identify Block Devices
&lt;/h3&gt;

&lt;p&gt;Block devices are marked with the &lt;strong&gt;&lt;code&gt;b&lt;/code&gt;&lt;/strong&gt; letter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This is an example of using &lt;code&gt;ls&lt;/code&gt; to identify a block device.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /dev/nvme0n1
brw-rw---- 1 root disk 259, 0 Jan  3 12:52 /dev/nvme0n1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Identify Character Devices
&lt;/h3&gt;

&lt;p&gt;Character devices are marked with the &lt;strong&gt;&lt;code&gt;c&lt;/code&gt;&lt;/strong&gt; letter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;An example of using &lt;code&gt;ls&lt;/code&gt; to identify a character device.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /dev/tty
crw-rw-rw- 1 root &lt;span class="nb"&gt;tty &lt;/span&gt;5, 0 Jan  7 18:22 /dev/tty
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Identify Socket Devices
&lt;/h3&gt;

&lt;p&gt;Sockets are marked with the &lt;strong&gt;&lt;code&gt;s&lt;/code&gt;&lt;/strong&gt; letter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;An example of using &lt;code&gt;ls&lt;/code&gt; to identify a socket device.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /run/systemd/notify
srwxrwxrwx 1 root root 0 Jan  3 12:52 /run/systemd/notify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  &lt;strong&gt;Links&lt;/strong&gt;
&lt;/h2&gt;

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

&lt;p&gt;Links are special types of files and there are two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Symbolic links:&lt;/strong&gt; These types of links point to other files or&lt;br&gt;
directories.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hard links:&lt;/strong&gt; These types of links point to the same place on the&lt;br&gt;
disk, known as inode, just as the original file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Symbolic Links
&lt;/h3&gt;

&lt;p&gt;A symbolic link is a special type of file pointing to another file's path. It's like a shortcut or alias.&lt;/p&gt;

&lt;h4&gt;
  
  
  Identify Symbolic Links
&lt;/h4&gt;

&lt;p&gt;Symbolic links are marked with the &lt;strong&gt;&lt;code&gt;l&lt;/code&gt;&lt;/strong&gt; letter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example of using &lt;code&gt;ls&lt;/code&gt; to identify a symbolic link.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /dev/core
lrwxrwxrwx 1 root root 11 Jan  3 12:52 /dev/core -&amp;gt; /proc/kcore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h4&gt;
  
  
  Creating Symbolic links
&lt;/h4&gt;

&lt;p&gt;The command used to create a symbolic link is &lt;code&gt;ln&lt;/code&gt; but with the &lt;code&gt;-s&lt;/code&gt;&lt;br&gt;
option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example that demonstrates how to create a symbolic file.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;target_file.txt
&lt;span class="nb"&gt;ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; target_file.txt the_soft_link.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To check the results use the command &lt;code&gt;ls -l&lt;/code&gt; as follows.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 root root  0 Nov  6 12:23 target_file.txt
lrwxrwxrwx 1 root root 15 Nov  6 11:54 the_soft_link.txt -&amp;gt; target_file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  Notes
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;  Symbolic links can point to a &lt;strong&gt;file&lt;/strong&gt; or &lt;strong&gt;directory&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  You can create symbolic links on different partitions.&lt;/li&gt;
&lt;li&gt;  You can create a symbolic link to a non-existent file.&lt;/li&gt;
&lt;li&gt;  Symbolic links are useful when you need to create a link to a file
or directory that is located on a different file system.&lt;/li&gt;
&lt;li&gt;  You can identify a symbolic link in the output of &lt;code&gt;ls&lt;/code&gt;, where the
first character on the permissions for a symbolic link is &lt;code&gt;'l'&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Access the man page for more info.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;ln&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Hard Links
&lt;/h3&gt;

&lt;p&gt;Hard links are pointers to the same &lt;code&gt;inode&lt;/code&gt; on the disk. This means that&lt;br&gt;
two different hard links can point to the same data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The &lt;code&gt;TARGET&lt;/code&gt; file must exist before creating a hard link.&lt;/li&gt;
&lt;li&gt;  If you do not specify a the_link_name a hard link with the same name
as the target_file will be created in the current directory.&lt;/li&gt;
&lt;li&gt;  When the target_file or the_link_name are not in the current
directory then use full path also known as absolute paths.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Creating Hard Links
&lt;/h4&gt;

&lt;p&gt;The command used to create hard links is the &lt;code&gt;ln&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;The basic syntax is shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ln &lt;/span&gt;target_file the_link_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this example we create a new file named &lt;code&gt;myfile&lt;/code&gt; and a new link named &lt;code&gt;mylink&lt;/code&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hi, there."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; myfile
&lt;span class="nb"&gt;ln &lt;/span&gt;myfile mylink
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Identify Hard Links
&lt;/h4&gt;

&lt;p&gt;Hard links do not have a special symbol that we can use to identify&lt;br&gt;
them. They are regular files. To identify hard links we use&lt;br&gt;
&lt;code&gt;ls&lt;/code&gt; with the &lt;code&gt;-i&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this step, we check the &lt;code&gt;inodes&lt;/code&gt; to make sure both files have the same &lt;code&gt;inode&lt;/code&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-il&lt;/span&gt; myfile
2027339 &lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 2 root root 11 Dec 31 08:29 myfile
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-il&lt;/span&gt; mylink
2027339 &lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 2 root root 11 Dec 31 08:29 mylink
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the number &lt;code&gt;2&lt;/code&gt;. That means two files point to the same inode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Another way to check that both files have the same &lt;code&gt;inodes&lt;/code&gt; is using the &lt;code&gt;stat&lt;/code&gt; command as follows.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"%n is a %F with inode %i"&lt;/span&gt; mylink
mylink is a regular file with inode 2027339

&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"%n is a %F with inode %i"&lt;/span&gt; myfile
myfile is a regular file with inode 2027339
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Notes on Hard Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  Hard links can be deleted using the &lt;code&gt;rm&lt;/code&gt; command. However, deleting
a hard link does not delete the underlying data as long as other
hard links are pointing to it.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;mv&lt;/code&gt; command can rename or move hard links. Since
they point to the same inode, they can be relocated freely without
affecting the data.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is no risk of "breaking" a hard link when moving it. As long&lt;br&gt;
as the inode remains accessible on the filesystem, the hard link&lt;br&gt;
will continue to point to the same data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can &lt;strong&gt;NOT&lt;/strong&gt; create a hard link to a directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can &lt;strong&gt;NOT&lt;/strong&gt; create a hard link to a file that is located on a&lt;br&gt;
different filesystem.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Access the man page for more info.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;ln&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;This article is part of my book: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://nedtechie.gumroad.com/l/Master_Linux_Permissions_While_Your_Coffee_Brews" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bca5kibedyv9dr210fh.jpg" title="Master Linux Permissions and File Types While Your Coffee Brews" alt="Master Linux Permissions and File Types While Your Coffee Brews" width="224" height="336"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>linux</category>
      <category>security</category>
      <category>lpi</category>
      <category>lpilinuxessentials</category>
    </item>
    <item>
      <title>Howto build Rootspace locally with buildx and bake</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Sun, 26 Mar 2023 07:55:32 +0000</pubDate>
      <link>https://dev.to/nedtechie/howto-build-rootspace-locally-with-buildx-and-bake-3gba</link>
      <guid>https://dev.to/nedtechie/howto-build-rootspace-locally-with-buildx-and-bake-3gba</guid>
      <description>&lt;p&gt;Lately, we have experimented with building Docker images for Rootspace with Docker buildx and bake since there is a great need to support multiple architectures.&lt;/p&gt;

&lt;p&gt;It is a significant improvements to the Docker build process as you create a build file definition and just invoke the build process.&lt;/p&gt;

&lt;p&gt;To start the project locally please follow the steps below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clone the project
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com:clearview/rootspace.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Build the images locally
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker buildx bake local --load
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check if the images have been built
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker image ls | grep root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Copy the .env files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp .env.example .env &amp;amp;&amp;amp; cp api/.env.example api/.env &amp;amp;&amp;amp; cp web/.env.example web/.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start the docker-compose local version
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker compose -f docker-compose.yml -f docker-compose-local.yml up --force-recreate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The project should be up.&lt;/p&gt;

</description>
      <category>rootspace</category>
      <category>docker</category>
      <category>buildx</category>
      <category>bake</category>
    </item>
    <item>
      <title>Monit to Slack notifications with Ansible</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Thu, 27 Oct 2022 13:40:38 +0000</pubDate>
      <link>https://dev.to/nedtechie/monit-to-slack-notifications-with-ansible-4e55</link>
      <guid>https://dev.to/nedtechie/monit-to-slack-notifications-with-ansible-4e55</guid>
      <description>&lt;p&gt;This post is a quick one where I share my Ansible playbook which installs Monit on the server, add space usage alerts with Slack notifications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
- hosts: all
  gather_facts: yes
  environment:
    PATH: /usr/local/rbenv/shims:{{ ansible_env.PATH }}
  roles:
  - role: zzet.rbenv
    tags: ['rbenv']
    rbenv_clean_up: false
    rbenv:
      env: system
      version: v1.2.0
      default_ruby: 3.0.4
      rubies:
        - version: 3.0.4
  - role: pgolm.monit
    tags: ['monit']
    vars:
      slack_webhook: "'https://hooks.slack.com/services/xxxx/xxxx/xxxx'"
      monit2slack_path: "/usr/local/rbenv/shims/monit2slack"
      monit_cycle: 120
      monit_webinterface_enabled: false
      monit_services:
      - name: disk_usage
        type: filesystem
        target: /
        rules:
          - 'if space usage &amp;gt; 90%
          then exec "{{monit2slack_path}} --webhook {{slack_webhook}} --status error"
          else if succeeded then exec "{{monit2slack_path}} --webhook {{slack_webhook}} --status ok"'
          - 'if inode usage &amp;gt; 90%
          then exec "{{monit2slack_path}} --webhook {{slack_webhook}} --status error"
          else if succeeded then exec "{{monit2slack_path}} --webhook {{slack_webhook}} --status ok"'
  tasks:
    - name: Update system gem
      command: gem update --system
      become: yes
      become_method: su
      become_user: root
      environment:
        PATH: "/usr/local/rbenv/bin:/usr/local/rbenv/shims:{{ ansible_env.PATH }}"

    - name: Install latest version of monit2slack
      gem:
        name: monit2slack
        state: latest
      environment:
        PATH: "/usr/local/rbenv/bin:/usr/local/rbenv/shims:{{ ansible_env.PATH }}"

    - name: Install monit2slack gem
      command: gem install monit2slack
      become: yes
      become_method: su
      become_user: root
      environment:
        PATH: "/usr/local/rbenv/bin:/usr/local/rbenv/shims:{{ ansible_env.PATH }}"

```

`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>monit</category>
      <category>ansible</category>
      <category>slack</category>
      <category>rbenv</category>
    </item>
    <item>
      <title>Get a Slack notification when your SSL certificate is about to expire</title>
      <dc:creator>Nedim Hadzimahmutovic</dc:creator>
      <pubDate>Fri, 20 Sep 2019 18:08:14 +0000</pubDate>
      <link>https://dev.to/nedtechie/get-a-slack-notification-when-your-ssl-certificate-is-about-to-expire-2c83</link>
      <guid>https://dev.to/nedtechie/get-a-slack-notification-when-your-ssl-certificate-is-about-to-expire-2c83</guid>
      <description>&lt;p&gt;I was tasked to finish a script to check the expiration of SSL certificates and post the notifications to our Slack channel. I wrote an Ansible playbook just to spice up everything. I had fun doing this so I will share the code hoping someone else might find it useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the Ansible playbook
&lt;/h2&gt;

&lt;p&gt;You must define &lt;code&gt;slack_webhook&lt;/code&gt; and &lt;code&gt;domains&lt;/code&gt; as both variables are required.&lt;/p&gt;

&lt;p&gt;Optionally configurable variables&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ssl_port&lt;/strong&gt; - standard is 443,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ssl_expiry_days_check&lt;/strong&gt; - the script starts warning if certificate is expiring in less than this period,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cron_period_check&lt;/strong&gt; - when the cron job shuld be run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example &lt;code&gt;ansible_ssl_check.yml&lt;/code&gt; playbook .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;server_name&lt;/span&gt;
  &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;user_group_directories&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;rvm&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;whenever&lt;/span&gt;
  &lt;span class="na"&gt;vars&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;slack_webhook&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://hooks.slack.com/services/xxxxxxx/xxxxxxx/xxxxxxxx"&lt;/span&gt;
    &lt;span class="na"&gt;domains&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;github.com&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;gitlab.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Testing
&lt;/h3&gt;

&lt;p&gt;If you want to test things out, and get some false positives, then change following variables&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ssl_expiry_days_check&lt;/code&gt; to something high like &lt;code&gt;'300'&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cron_period_check&lt;/code&gt; to &lt;code&gt;'hourly'&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Run the playbook
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add the server to Ansible inventory file and then run the command below.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ansible-playbook -i hosts playbok.yml
```

`

This command assumes the hosts inventory file is in the current directory.

### Slack notifications

Your notifications will look like this.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/9iqwr9ylae8xj3fpybp5.png)

### Code repository

You can find the Gitub repo [here](https://github.com/neidiom/ansible_ssl_expiry_check).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ansible</category>
      <category>slack</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
