<?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: TechBobby</title>
    <description>The latest articles on DEV Community by TechBobby (@techbobby).</description>
    <link>https://dev.to/techbobby</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4275185%2F0f46add4-97e4-4b2c-a6a2-3e8d74505fbd.png</url>
      <title>DEV Community: TechBobby</title>
      <link>https://dev.to/techbobby</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/techbobby"/>
    <language>en</language>
    <item>
      <title>EACCES errno 13: which bit, which directory, and how to fix it</title>
      <dc:creator>TechBobby</dc:creator>
      <pubDate>Mon, 30 Nov 2026 23:46:42 +0000</pubDate>
      <link>https://dev.to/techbobby/eacces-errno-13-which-bit-which-directory-and-how-to-fix-it-5363</link>
      <guid>https://dev.to/techbobby/eacces-errno-13-which-bit-which-directory-and-how-to-fix-it-5363</guid>
      <description>&lt;p&gt;Every "Permission denied" in a log is the same three words and almost never the same cause. &lt;code&gt;EACCES&lt;/code&gt; is errno 13, and the kernel uses that one number for four different decisions. Once you know which four, the message stops being a dead end — and &lt;code&gt;chmod 777&lt;/code&gt; often still changes nothing, because it misses three of them.&lt;/p&gt;

&lt;p&gt;I measured all four on one Linux host — 38 calls, each repeated five times, as uid 1000 on kernel 6.12.118 — and wrote the kernel's decision out as a small Python module so a program can say &lt;em&gt;which&lt;/em&gt; bit will deny a call before making it. Here is the short version: what to check, and in what order.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four rules behind one number
&lt;/h2&gt;

&lt;p&gt;Of the 38 calls in the matrix, 21 answered 13 and 9 succeeded. Those 21 come from four rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The object's own bits deny the class that applies.&lt;/strong&gt; A &lt;code&gt;0400&lt;/code&gt; file opened for write answers 13 — the owner class has no &lt;code&gt;w&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An ancestor directory has no &lt;code&gt;x&lt;/code&gt;.&lt;/strong&gt; A &lt;code&gt;0444&lt;/code&gt; directory refused both the &lt;code&gt;open&lt;/code&gt; and the &lt;code&gt;stat&lt;/code&gt; of a perfectly ordinary &lt;code&gt;0644&lt;/code&gt; file inside it. The file's mode was never consulted, because the walk never arrived.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The object belongs to another account and the other-class bits are clear.&lt;/strong&gt; A &lt;code&gt;0755&lt;/code&gt; file owned by root gives uid 1000 nothing to write with: 13.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What is missing is a privilege, not a bit.&lt;/strong&gt; Ports below 1024 need a capability; a read-only mount refuses with &lt;code&gt;EROFS&lt;/code&gt; (30) before anyone looks at a mode.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Rules 1 to 3 are the same nine bits read three ways. Rule 4 is the one that makes people edit the wrong thing for an hour.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with one strace, not with chmod
&lt;/h2&gt;

&lt;p&gt;The log line says &lt;em&gt;what&lt;/em&gt; failed. One command says &lt;em&gt;which call&lt;/em&gt; failed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;strace -Z -f -e &lt;span class="nv"&gt;trace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;%file ./your-service --the-command-that-fails
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-Z&lt;/code&gt; keeps only the calls that returned an error (&lt;code&gt;-z&lt;/code&gt; is its opposite, only the successful ones; both arrived in strace 5.2 as aliases of &lt;code&gt;-e status=&lt;/code&gt;). &lt;code&gt;%file&lt;/code&gt; keeps the calls that take a path. The failing line is the kernel's own account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openat(AT_FDCWD, "/srv/app/upload", O_WRONLY|O_CREAT, 0666) = -1 EACCES (Permission denied)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The flags beside the path are the access the process asked for, which a log line drops. What the trace still cannot say is &lt;em&gt;which component&lt;/em&gt; of the path refused, because the kernel reports the path the call passed and not the step it stopped at. That gap is what the walk below fills.&lt;/p&gt;

&lt;p&gt;One honest note from my own host: &lt;code&gt;strace&lt;/code&gt; was not installed, and a binary unpacked from the Debian package was refused &lt;code&gt;ptrace&lt;/code&gt; by the container's seccomp profile. The trace line above is quoted from the tool's documentation, not captured on that machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: the class is chosen before a bit is read
&lt;/h2&gt;

&lt;p&gt;The kernel never asks "is this file writable". It asks which third of the mode word belongs to your process: the &lt;strong&gt;owner&lt;/strong&gt; bits if the effective uid matches the file's owner, the &lt;strong&gt;group&lt;/strong&gt; bits if the gid or any supplementary group matches, otherwise the &lt;strong&gt;other&lt;/strong&gt; bits. Only that triplet counts.&lt;/p&gt;

&lt;p&gt;That ordering is why a mode can lock out its own owner. On this host, with a &lt;code&gt;0644&lt;/code&gt; file inside each directory:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory mode&lt;/th&gt;
&lt;th&gt;A &lt;code&gt;0644&lt;/code&gt; file inside it&lt;/th&gt;
&lt;th&gt;&lt;code&gt;open(O_RDONLY)&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;stat&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0777&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;untouched&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0077&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;untouched&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;13&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;13&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0700&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;untouched&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A directory at &lt;code&gt;0077&lt;/code&gt; — group and other wide open, owner triplet cleared — refused the account that &lt;em&gt;owned&lt;/em&gt; it. Nobody would ask a stranger in, but ownership selects which three bits are read, so clearing the owner triplet locks the owner out.&lt;/p&gt;

&lt;p&gt;The file can do the same thing on its own: every directory above it at &lt;code&gt;0755&lt;/code&gt;, the file at &lt;code&gt;0077&lt;/code&gt;, and a read answered 13.&lt;/p&gt;

&lt;p&gt;Both repair the same way — put the owner triplet back, do not widen anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod u+rwX /srv/app/upload           &lt;span class="c"&gt;# the bits the owner needs, nothing more&lt;/span&gt;
namei -l /srv/app/upload/report.csv   &lt;span class="c"&gt;# and every component on the way there&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rule 2: x on every directory in the path
&lt;/h2&gt;

&lt;p&gt;Directory &lt;code&gt;x&lt;/code&gt; is &lt;em&gt;search&lt;/em&gt; permission, and it is asked for separately from anything about the file. Every component of the path needs it, including the last directory before the file.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory mode&lt;/th&gt;
&lt;th&gt;What was asked of it&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0444&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;open a &lt;code&gt;0644&lt;/code&gt; file inside&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0111&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;open a &lt;code&gt;0644&lt;/code&gt; file inside&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0444&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;stat&lt;/code&gt; that file&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0111&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;chdir&lt;/code&gt; into the directory&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0333&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;list its entries&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0555&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;list its entries&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A &lt;code&gt;0444&lt;/code&gt; directory (readable, not searchable) is useless to the files inside it, while &lt;code&gt;0111&lt;/code&gt; (searchable, not readable) lets them be opened but not listed. That is also why &lt;code&gt;ls&lt;/code&gt; can print names where &lt;code&gt;ls -l&lt;/code&gt; prints question marks — names need &lt;code&gt;r&lt;/code&gt;, metadata needs &lt;code&gt;x&lt;/code&gt; on the path.&lt;/p&gt;

&lt;p&gt;Symbolic links are the third version of the same trap: a link carries &lt;code&gt;0777&lt;/code&gt; and the kernel ignores it entirely. What counts is the directory holding the link and the mode of the target, so a link pointing at a &lt;code&gt;0644&lt;/code&gt; file from inside a &lt;code&gt;0000&lt;/code&gt; directory answers 13 — which reads like a problem with the target.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: ownership, and the container case
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;other&lt;/code&gt; class is where containers usually land: a volume mounted at &lt;code&gt;0755&lt;/code&gt; and owned by another uid gives the service nothing to write with, and the service reports 13 on its own working directory. Before blaming the application, compare &lt;code&gt;stat -c '%u:%g %a %n' /var/lib/app/data&lt;/code&gt; with &lt;code&gt;id -u&lt;/code&gt;. If the uid differs, &lt;code&gt;chown -R&lt;/code&gt; the mount to the runtime uid or mount it with that uid — no &lt;code&gt;chmod&lt;/code&gt; on the child files fixes a class problem.&lt;/p&gt;

&lt;p&gt;One distinction worth keeping: &lt;code&gt;chmod&lt;/code&gt; by a non-owner answers &lt;code&gt;EPERM&lt;/code&gt; (1), not 13, because ownership is checked before any bit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 4: when no bit is the answer
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Number&lt;/th&gt;
&lt;th&gt;What it actually is&lt;/th&gt;
&lt;th&gt;The call that answered it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;the object's bits deny the class&lt;/td&gt;
&lt;td&gt;read a &lt;code&gt;0400&lt;/code&gt; file for write&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;an ancestor has no &lt;code&gt;x&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;open a &lt;code&gt;0644&lt;/code&gt; file through a &lt;code&gt;0444&lt;/code&gt; directory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;other-class bits are clear&lt;/td&gt;
&lt;td&gt;write a root-owned &lt;code&gt;0755&lt;/code&gt; file as uid 1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;a privilege, not a mode&lt;/td&gt;
&lt;td&gt;bind port 80 as a service user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;ownership&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;chmod&lt;/code&gt; a root file as uid 1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;the mount is read-only&lt;/td&gt;
&lt;td&gt;create in &lt;code&gt;/usr&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;the name does not exist&lt;/td&gt;
&lt;td&gt;open a name that was never there&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;the name already exists&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;O_CREAT&lt;/code&gt; plus &lt;code&gt;O_EXCL&lt;/code&gt; on an occupied name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;executable, but not in a format the kernel can run&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;execve&lt;/code&gt; a text file with &lt;code&gt;x&lt;/code&gt; set&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;EROFS&lt;/code&gt; changes the order of your checks. &lt;code&gt;/usr&lt;/code&gt; on that host is a read-only overlay, so a create there answered 30, and a &lt;code&gt;chmod&lt;/code&gt; under it answered 30 rather than the 1 it gives on a writable filesystem. The mount comes before ownership, and ownership before any mode — a runbook that starts with &lt;code&gt;chmod&lt;/code&gt; starts in the wrong place. &lt;code&gt;ENOEXEC&lt;/code&gt; (8) is the quiet one: a script without a shebang, made executable, answers 8 rather than 13.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete is a directory permission
&lt;/h2&gt;

&lt;p&gt;Creating, renaming and deleting are operations on a &lt;em&gt;name&lt;/em&gt;, and names live in directories. Each needs &lt;code&gt;w&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt; on the directory that holds the name. The file's own mode never enters the decision:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Directory mode&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;unlink a &lt;code&gt;0444&lt;/code&gt; file&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0755&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unlink a &lt;code&gt;0644&lt;/code&gt; file&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0555&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;create a file&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0555&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mkdir&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0555&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The sticky bit narrows that rule further: with it set (&lt;code&gt;1777&lt;/code&gt;, like &lt;code&gt;/tmp&lt;/code&gt;), a name may be changed only by the name's owner, the directory's owner, or a process with the capability to override both. My attempt to isolate it failed honestly — a rename out of &lt;code&gt;/tmp&lt;/code&gt; answered 13, but the name lives in &lt;code&gt;/&lt;/code&gt; at &lt;code&gt;0755&lt;/code&gt; root, so the parent refused it before the sticky bit was read. That rule is quoted from the manual, not measured.&lt;/p&gt;

&lt;h2&gt;
  
  
  Naming the component, not the number
&lt;/h2&gt;

&lt;p&gt;The trace names the call; the kernel will not name the component. A program can, because every component is stat-able and the decision is a function of modes and ids visible from outside. The core of it is one function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;granted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;klass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""The (read, write, execute) bits that apply to one identity class."""&lt;/span&gt;
    &lt;span class="n"&gt;shift&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"owner"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"other"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;klass&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pick the class, map the operation onto the bits it needs, walk the path in order, and report the first component that refuses with its mode, its class and the bit it wanted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;permwhy&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Want&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;explain&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;explain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/srv/app/upload/report.csv"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Want&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;WRITE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"nothing refuses"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# /srv/app/upload: no write permission on the directory (mode 0555, w+x)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Against the kernel that walk agreed on 17 of 17 in-scope arms — including the case with two closed components, where the kernel answers one number and a reader would otherwise debug the wrong directory. It is a prediction, not a guarantee: ACLs, SELinux labels, the immutable attribute, a read-only mount and NFS &lt;code&gt;root_squash&lt;/code&gt; are all checked after these nine bits.&lt;/p&gt;

&lt;h2&gt;
  
  
  One measurement worth keeping
&lt;/h2&gt;

&lt;p&gt;A refusal is not slow: a refused &lt;code&gt;open&lt;/code&gt; took a median 1.74 µs against 1.32 µs for the same call that succeeded, so a service that retries one burns almost the CPU of a successful call and surfaces the failure as load instead of an error rate. A quarter second of retrying made 151,052 attempts and succeeded 0 times. The bits do not change because a process asks again — a backoff only spreads out the certainty.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Read the errno: 13, 1, 30, 2 and 8 mean five different things.&lt;/li&gt;
&lt;li&gt;Check the mount (&lt;code&gt;ro&lt;/code&gt;?) and the ownership before touching a mode.&lt;/li&gt;
&lt;li&gt;Walk the path, not the file: &lt;code&gt;namei -l&lt;/code&gt;, and &lt;code&gt;x&lt;/code&gt; on every directory.&lt;/li&gt;
&lt;li&gt;Read the class first — owner, group, other. Widening the wrong triplet changes nothing.&lt;/li&gt;
&lt;li&gt;For delete, create and rename, look at the directory.&lt;/li&gt;
&lt;li&gt;Fix the first component that refuses, with the smallest bit that fixes it.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Full benchmark tables, 91 tests, and appendix code for the walk: &lt;a href="https://techbobby.com/eacces-errno-13-permission-denied-which-bit-directory-runbook/" rel="noopener noreferrer"&gt;EACCES errno 13: the Bit, the Directory, and the chmod That Ends It&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>python</category>
      <category>debugging</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
