<?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: Asad Ali</title>
    <description>The latest articles on DEV Community by Asad Ali (@asad_ali).</description>
    <link>https://dev.to/asad_ali</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%2F4224868%2F5f486e54-456e-4f6e-928d-45b2f1f398f1.jpg</url>
      <title>DEV Community: Asad Ali</title>
      <link>https://dev.to/asad_ali</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asad_ali"/>
    <language>en</language>
    <item>
      <title>How I Compress PDFs in the Browser While Keeping Text Selectable</title>
      <dc:creator>Asad Ali</dc:creator>
      <pubDate>Fri, 27 Nov 2026 18:48:47 +0000</pubDate>
      <link>https://dev.to/asad_ali/how-i-compress-pdfs-in-the-browser-while-keeping-text-selectable-pf0</link>
      <guid>https://dev.to/asad_ali/how-i-compress-pdfs-in-the-browser-while-keeping-text-selectable-pf0</guid>
      <description>&lt;p&gt;Two 5 MB PDFs can look identical at page width. Try copying a part number. In a scanned manual, the letters may be pixels in a photograph. In a report exported from a word processor, an embedded font can draw the same letters as selectable glyphs.&lt;/p&gt;

&lt;p&gt;I built the &lt;a href="https://offlinefilelab.com/tools/compress-pdf/" rel="noopener noreferrer"&gt;browser PDF compressor&lt;/a&gt; around that distinction. Both modes start with a worker that optimises existing PDF objects. Choosing Extreme allows a second pass that renders whole pages if the first pass misses the byte budget.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Smart mode can shrink
&lt;/h2&gt;

&lt;p&gt;A PDF page can draw an image by referring to a separate object that contains the encoded pixels. That indirection gives the compressor a useful place to intervene. If a report includes a three-megapixel photograph displayed at the width of a business card, a smaller JPEG can occupy the same rectangle. The caption beneath it still uses the original text operators and font.&lt;/p&gt;

&lt;p&gt;The worker loads the document with pdf-lib, discards selected metadata and thumbnails, collects unreachable objects and merges byte-identical streams. Consider a logo that an exporter embedded afresh on every page. Pointing those references to one copy saves space without degrading the logo. The worker also trims excess decimal precision in supported drawing streams. Even a document with no photographs can benefit from these steps.&lt;/p&gt;

&lt;p&gt;For images, the worker recognises a limited set of encodings and colour models. It can decode eligible JPEG streams and certain eight-bit, deflate-compressed images. It skips tiny decorations and leaves colour models such as CMYK alone. For each candidate, it tries JPEG quality and dimension limits in order, starting at quality 0.82 with a longest side of 2,600 pixels. A trial that makes an individual image larger buys us nothing. This is the guard inside the replacement loop in &lt;code&gt;src/workers/pdf-compress.worker.ts&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chosen&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;oldLen&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There’s a separate trade-off for tagged PDFs. If the document is still above target, the worker can remove its structure tree. A paragraph can remain selectable even after it loses information a screen reader uses for navigation. If I’m preparing an accessible publication, copying a sentence is only one check. I also check the reading order and headings in the resulting document and keep the tagged original.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Extreme mode actually draws a page
&lt;/h2&gt;

&lt;p&gt;Extreme mode returns the vector result immediately if it fits. When that pass misses the target, the UI opens a fresh copy of the original bytes with PDF.js. Going back to the original matters here. Rendering an image that Smart has already downsampled would spend another generation of JPEG loss before we had even chosen the final resolution.&lt;/p&gt;

&lt;p&gt;The following three lines are from &lt;code&gt;src/tools/CompressPdf.tsx&lt;/code&gt;. Here, &lt;code&gt;vp&lt;/code&gt; is the viewport at scale one and &lt;code&gt;RENDER_SCALE&lt;/code&gt; is 1.5.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RENDER_SCALE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2400&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;renderPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createImageBitmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;widthPt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;vp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;heightPt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;vp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&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;On an ordinary page, 1.5 times 72 PDF points per inch gives a nominal 108 DPI. The 2,400-pixel cap also bounds the longest edge of an unusually large page. The UI releases each HTML canvas after creating its bitmap and transfers the bitmaps to the worker. The worker uses OffscreenCanvas to try smaller dimensions and JPEG settings without asking PDF.js to draw the source document again.&lt;/p&gt;

&lt;p&gt;At each resolution the worker tests the lowest quality in the tier. If that fits its byte estimate, it searches for a higher quality at the same resolution. Extreme can go as low as a nominal 36 DPI on an uncapped page, where a decimal point or the tail of a digit can disappear. Finally, pdf-lib creates pages at their original physical dimensions and draws one JPEG across each. A page built that way has no embedded text to select. If flattening produces a larger result than Smart, the UI keeps the vector version. The final size comparison can also return the original file.&lt;/p&gt;

&lt;h2&gt;
  
  
  A two-file benchmark
&lt;/h2&gt;

&lt;p&gt;Use the &lt;a href="https://offlinefilelab.com/tools/compress-pdf/to-200kb/" rel="noopener noreferrer"&gt;200 KB preset&lt;/a&gt; for both modes. Its budget is 204,800 bytes. Start each run with the original and measure the downloaded file in bytes. Use a scan without an OCR layer for one input and a document with a known selectable phrase for the other. For each output, try copying that phrase with automatic OCR disabled. A viewer that recognises text in pictures can otherwise hide what the compressor did.&lt;/p&gt;

&lt;p&gt;I ran both modes through the exported app in Chrome 158.0.8127.37. The scan was a synthetic US Letter service record with twelve 1,000 × 1,300 JPEGs, one per page. The text fixture had 32 Letter pages with 40 lines of 11-point Helvetica per page. I reopened each downloaded Blob with PDF.js and checked whether page one had an extractable “Service record” phrase. That tests the embedded text layer independently of a viewer’s OCR.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sample&lt;/th&gt;
&lt;th&gt;Original Size&lt;/th&gt;
&lt;th&gt;Smart Mode Size&lt;/th&gt;
&lt;th&gt;Text Selectable?&lt;/th&gt;
&lt;th&gt;Extreme Mode Size&lt;/th&gt;
&lt;th&gt;Text Selectable?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Raster scans, 12 pages&lt;/td&gt;
&lt;td&gt;10,428,319 B&lt;/td&gt;
&lt;td&gt;366,425 B&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;190,995 B&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Text report, 32 pages&lt;/td&gt;
&lt;td&gt;15,688 B&lt;/td&gt;
&lt;td&gt;15,446 B&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;15,446 B&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To recreate the fixtures, draw “Service record P / entry N” with one-based page and entry numbers. For the report, place lines at x = 40 and y = 750 − 18k points, starting with k = 0. For each scan, draw 32 lines in black 24 px Arial at (45, 65 + 36k) over grey noise. Seed the noise with the page number, advance once per pixel using (1664525 × seed + 1013904223) modulo 2³², and add 185 to the top six bits for each grey value. Embed the canvas as a JPEG at quality 0.96 across a 612 × 792 point page. Both fixtures used pdf-lib’s default save settings with metadata updates disabled. Browser JPEG encoders and installed fonts can affect the exact byte count.&lt;/p&gt;

&lt;p&gt;The scan needed flattening to meet the limit and had no text layer to lose. The report fit on the first pass. Extreme returned the same selectable version because spending pixels on those 1,280 lines would serve no purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test it in Airplane Mode
&lt;/h2&gt;

&lt;p&gt;Load the page while connected and run a disposable example that reaches the raster stage so the browser fetches the lazy-loaded PDF.js code and its worker. Keep the tab open, disconnect all network interfaces, then select a different local PDF, compress it and open the download. Starting with a fresh file after disconnecting is the important part of the test. The app reads the file into browser memory, processes it there and creates a downloadable Blob. There’s no backend upload endpoint in that path. For my support workflow, the last check is mundane but decisive. Can I still copy the part number that prompted me to share the document?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Built by **Asad Ali&lt;/em&gt;* — IT Support &amp;amp; Security Operations Engineer (Microsoft SC-200 &amp;amp; ISC2 CC Certified). Creator of &lt;a href="https://offlinefilelab.com/" rel="noopener noreferrer"&gt;OfflineFileLab.com&lt;/a&gt; and &lt;a href="https://localsectools.com/" rel="noopener noreferrer"&gt;LocalSecTools.com&lt;/a&gt; — 100% client-side privacy and security workbenches where sensitive files and logs never leave your browser. Portfolio: &lt;a href="https://asadali.tech/" rel="noopener noreferrer"&gt;asadali.tech&lt;/a&gt;*&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>nextjs</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Fixing Linux Permission Denied Errors &amp; Decoding Base64 Logs Locally (Without chmod 777 or Third-Party Web Servers)</title>
      <dc:creator>Asad Ali</dc:creator>
      <pubDate>Tue, 10 Nov 2026 17:29:48 +0000</pubDate>
      <link>https://dev.to/asad_ali/fixing-linux-permission-denied-errors-decoding-base64-logs-locally-without-chmod-777-or-1jko</link>
      <guid>https://dev.to/asad_ali/fixing-linux-permission-denied-errors-decoding-base64-logs-locally-without-chmod-777-or-1jko</guid>
      <description>&lt;p&gt;Two shortcuts show up in almost every infrastructure audit I review. The first is a directory set to &lt;code&gt;777&lt;/code&gt; because a deploy failed once. The second is an internal log line pasted into a random online decoder because someone needed an answer quickly.&lt;/p&gt;

&lt;p&gt;Both shortcuts solve the immediate problem and create a compliance finding. This guide covers the proper fix for the most common &lt;code&gt;Permission denied&lt;/code&gt; errors, a least-privilege reference matrix, and how to decode logs and tokens without them leaving your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do chmod 777 and 666 fail production audits?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mode 777 gives every account on the host read, write and execute access, and 666 gives every account read and write.&lt;/strong&gt; Least-privilege standards such as the CIS Benchmarks flag world-writable files because any process on the host can change them. The fix is almost always ownership, not wider permissions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where 777 usually comes from
&lt;/h3&gt;

&lt;p&gt;Nobody chooses 777 as a design decision. It appears when a permission error blocks a deploy and widening access makes the error go away. Three scenarios cause most of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker bind mounts.&lt;/strong&gt; The container process runs as one UID, while the host directory belongs to another. The app reports &lt;code&gt;EACCES&lt;/code&gt;, and someone runs &lt;code&gt;chmod -R 777 ./data&lt;/code&gt; on the host. Check the numbers first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls -lan ./data
docker run --rm myimage id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the container runs as UID 999 and the directory belongs to UID 1000, fix the ownership or the runtime user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo chown -R 999:999 ./data
&lt;span class="c"&gt;# or run the container as the host user&lt;/span&gt;
docker run --user &lt;span class="s2"&gt;"$(id -u):$(id -g)"&lt;/span&gt; -v &lt;span class="s2"&gt;"$PWD/data:/var/lib/app"&lt;/span&gt; myimage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Nginx and PHP-FPM sockets.&lt;/strong&gt; The Nginx error log shows a line like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() to unix:/run/php/php8.2-fpm.sock failed (13: Permission denied) while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Setting the socket to 777 hides the problem until the next FPM restart recreates it. The durable fix lives in the pool config, usually &lt;code&gt;/etc/php/8.2/fpm/pool.d/www.conf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="na"&gt;listen.owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
&lt;span class="na"&gt;listen.group&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
&lt;span class="na"&gt;listen.mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0660&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart FPM, then confirm the result with &lt;code&gt;stat -c "%a %U:%G %n" /run/php/php8.2-fpm.sock&lt;/code&gt;. You should see &lt;code&gt;660 www-data:www-data&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CI/CD runner workspaces.&lt;/strong&gt; A containerized build step on a self-hosted runner writes files as root. The next checkout fails because the runner user cannot delete them. Instead of adding &lt;code&gt;chmod -R 777&lt;/code&gt; to the pipeline, run the build container as the runner's UID, or add a cleanup step that restores ownership with &lt;code&gt;chown&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The 9-bit math behind the finding
&lt;/h3&gt;

&lt;p&gt;A Unix mode has nine permission bits in three groups: owner, group and others. Each group uses the same weights.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = 4    w = 2    x = 1        digit = r + w + x

777  -&amp;gt;  111 111 111  -&amp;gt;  rwx rwx rwx
770  -&amp;gt;  111 111 000  -&amp;gt;  rwx rwx ---
666  -&amp;gt;  110 110 110  -&amp;gt;  rw- rw- rw-
644  -&amp;gt;  110 100 100  -&amp;gt;  rw- r-- r--
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare 777 with 770. The only difference is the last group of three bits, the "others" scope. Those bits cover every account that is neither the owner nor in the group: unrelated services, other tenants on a shared host, and automation you forgot was running.&lt;/p&gt;

&lt;p&gt;When "others" can write a configuration file, any of those processes can change how your application behaves. That is why auditors treat world-writable files as a finding, even when nothing has gone wrong yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Auditing a host for world-writable files
&lt;/h3&gt;

&lt;p&gt;These read-only commands list what an auditor would flag. They stay on one filesystem and skip &lt;code&gt;/proc&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="c"&gt;# world-writable regular files&lt;/span&gt;
sudo find / -xdev -type f -perm -0002 -printf &lt;span class="s1"&gt;'%m %u:%g %p\n'&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null

&lt;span class="c"&gt;# world-writable directories without the sticky bit&lt;/span&gt;
sudo find / -xdev -type d -perm -0002 ! -perm -1000 -printf &lt;span class="s1"&gt;'%m %u:%g %p\n'&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Directories such as &lt;code&gt;/tmp&lt;/code&gt; are world-writable by design, but they carry the sticky bit (&lt;code&gt;1777&lt;/code&gt;). That bit stops users from deleting each other's files, which is why the second command excludes it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the least-privilege permission matrix?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Give each file type the smallest mode that still lets its owner and service do their job.&lt;/strong&gt; For most production hosts, six modes cover nearly everything. The table below maps each one to the files it belongs on.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;ls -l&lt;/code&gt; view&lt;/th&gt;
&lt;th&gt;Binary&lt;/th&gt;
&lt;th&gt;Use it for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;700&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;drwx------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;111 000 000&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;~/.ssh&lt;/code&gt; and isolated per-user folders&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;600&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-rw-------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;110 000 000&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;~/.ssh/id_ed25519&lt;/code&gt;, &lt;code&gt;.env&lt;/code&gt; files, TLS private keys&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;400&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-r--------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;100 000 000&lt;/td&gt;
&lt;td&gt;Cloud &lt;code&gt;.pem&lt;/code&gt; keypairs, immutable config files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;770&lt;/code&gt; / &lt;code&gt;2770&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;drwxrwx---&lt;/code&gt; / &lt;code&gt;drwxrws---&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;111 111 000&lt;/td&gt;
&lt;td&gt;Shared deployment directories (&lt;code&gt;deploy:www-data&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;555&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-r-xr-xr-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;101 101 101&lt;/td&gt;
&lt;td&gt;Read-only executable binaries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;000&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;----------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;000 000 000&lt;/td&gt;
&lt;td&gt;Locked archive files&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a visual version of each row, the &lt;a href="https://localsectools.com/tools/chmod-calculator/700/" rel="noopener noreferrer"&gt;chmod 700 octal and symbolic permission breakdown&lt;/a&gt; and the &lt;a href="https://localsectools.com/tools/chmod-calculator/600/" rel="noopener noreferrer"&gt;chmod 600 SSH key permission calculator&lt;/a&gt; show the bits, the symbolic string and the matching commands side by side.&lt;/p&gt;

&lt;h3&gt;
  
  
  Applying the matrix from the CLI
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;SSH directory and keys.&lt;/strong&gt; OpenSSH refuses keys that other accounts can read, so these two modes matter in practice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/config
stat -c &lt;span class="s2"&gt;"%a %n"&lt;/span&gt; ~/.ssh ~/.ssh/id_ed25519
&lt;span class="c"&gt;# 700 /home/deploy/.ssh&lt;/span&gt;
&lt;span class="c"&gt;# 600 /home/deploy/.ssh/id_ed25519&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Environment files and TLS keys.&lt;/strong&gt; The service account that reads them should own them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo chown app:app /srv/app/.env
sudo chmod 600 /srv/app/.env /etc/ssl/private/app.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cloud keypairs.&lt;/strong&gt; Use 400 so even the owner cannot overwrite the key by accident:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod 400 ~/keys/staging-ec2.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Shared deployment directories with setgid.&lt;/strong&gt; Here the &lt;code&gt;deploy&lt;/code&gt; user owns the tree and the &lt;code&gt;www-data&lt;/code&gt; group can work in it. The leading &lt;code&gt;2&lt;/code&gt; sets the setgid bit, so new files inherit the &lt;code&gt;www-data&lt;/code&gt; group automatically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo install -d -o deploy -g www-data -m 2770 /srv/releases
ls -ld /srv/releases
&lt;span class="c"&gt;# drwxrws--- 2 deploy www-data 4096 Nov 10 09:12 /srv/releases&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lowercase &lt;code&gt;s&lt;/code&gt; in the group position confirms setgid is active. Pair it with a umask of &lt;code&gt;0007&lt;/code&gt; for the deploy process, so new files are group-writable but closed to others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Binaries and archives.&lt;/strong&gt; Mode 555 lets everyone run a binary but nobody edit it. Mode 000 parks an archive until someone deliberately restores access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo chmod 555 /usr/local/bin/report-agent
sudo chmod 000 /srv/archive/2025-q4.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Root still bypasses read and write checks, and the owner can always run &lt;code&gt;chmod&lt;/code&gt; again. Treat 000 and 555 as guardrails against mistakes, not as a security boundary.&lt;/p&gt;

&lt;p&gt;When I need to convert between octal and symbolic notation quickly, I use this &lt;a href="https://localsectools.com/tools/chmod-calculator/" rel="noopener noreferrer"&gt;client-side Linux Chmod Calculator&lt;/a&gt;. The reasoning behind each mode is covered in the &lt;a href="https://localsectools.com/blog/chmod-000-400-555-600-666-770-linux-permissions-guide/" rel="noopener noreferrer"&gt;complete Linux chmod 000, 400, 555, 600, 666, and 770 permissions guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do you decode Base64 logs and JWTs without sending them to a server?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Decode them with local tools: &lt;code&gt;base64&lt;/code&gt; and &lt;code&gt;iconv&lt;/code&gt; in a shell, or browser APIs that never make a network request.&lt;/strong&gt; A server-side decoder receives everything you paste as a request body. After that, your data sits under someone else's logging and retention policy.&lt;/p&gt;

&lt;h3&gt;
  
  
  What actually leaves your machine
&lt;/h3&gt;

&lt;p&gt;Diagnostic data is more sensitive than it looks. A Windows Event 4625 line includes account names, workstation names and source IP addresses. Nginx and syslog entries reveal internal hostnames, paths and request patterns.&lt;/p&gt;

&lt;p&gt;Even a benign PowerShell automation script, stored as an &lt;code&gt;-EncodedCommand&lt;/code&gt; string, can contain server names and share paths. A staging &lt;code&gt;Bearer&lt;/code&gt; JWT carries user IDs and roles, and it may still be valid when you paste it. Ad-supported decoder sites also tend to load third-party scripts, and some of those record what you type into form fields.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decoding UTF-16LE Base64 in bash
&lt;/h3&gt;

&lt;p&gt;PowerShell's &lt;code&gt;-EncodedCommand&lt;/code&gt; expects Base64 of UTF-16LE text, not UTF-8. That is why a plain &lt;code&gt;base64 -d&lt;/code&gt; prints text with null bytes between the letters. Convert the encoding with &lt;code&gt;iconv&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;echo&lt;/span&gt; &lt;span class="s1"&gt;'RwBlAHQALQBTAGUAcgB2AGkAYwBlAA=='&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; base64 -d &lt;span class="o"&gt;|&lt;/span&gt; iconv -f UTF-16LE -t UTF-8
&lt;span class="c"&gt;# Get-Service&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gzip-compressed Base64 blobs need one more step:&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;"$BLOB"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; base64 -d &lt;span class="o"&gt;|&lt;/span&gt; gunzip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To inspect a JWT's claims, decode the middle segment. JWTs use URL-safe Base64 without padding, so Python handles it more reliably than &lt;code&gt;base64 -d&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;python3 -c &lt;span class="s2"&gt;"import sys,base64,json; p=sys.argv[1].split('.')[1]; print(json.dumps(json.loads(base64.urlsafe_b64decode(p+'='*(-len(p)%4))), indent=2))"&lt;/span&gt; &lt;span class="s2"&gt;"$JWT"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Doing the same work inside a browser tab
&lt;/h3&gt;

&lt;p&gt;Modern browsers ship the same capabilities as built-in APIs. Code that uses them runs entirely in the page, with no request carrying your input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// UTF-16LE Base64 -&amp;gt; text&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;atob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b64&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="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&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="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextDecoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'utf-16le'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// gzip Base64 -&amp;gt; text&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;bytes&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="nf"&gt;stream&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="nf"&gt;pipeThrough&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DecompressionStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'gzip'&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;unzipped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&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="c1"&gt;// HS256 JWT signature check with a staging secret that never leaves the tab&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;importKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'raw'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextEncoder&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="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret&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="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'HMAC'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'SHA-256'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'verify'&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;atob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/-/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'+'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/'&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&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="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;valid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'HMAC'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextEncoder&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="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${h}.${p}`&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;&lt;code&gt;TextDecoder&lt;/code&gt; handles character encodings, &lt;code&gt;DecompressionStream&lt;/code&gt; handles gzip and deflate, and &lt;code&gt;crypto.subtle&lt;/code&gt; handles signature checks. Together they cover most log and token inspection work without a backend.&lt;/p&gt;

&lt;p&gt;You can confirm any tool behaves this way. Open DevTools, clear the Network tab, paste your input and run the tool. If no request contains your data, and the tool still works with Wi-Fi off, the processing is local.&lt;/p&gt;

&lt;p&gt;That is the approach behind the &lt;a href="https://localsectools.com/tools/log-deobfuscator/" rel="noopener noreferrer"&gt;offline PowerShell Base64 and gzip Log De-obfuscator&lt;/a&gt;, which detects the encoding layers and unwraps them in the tab. The &lt;a href="https://localsectools.com/tools/jwt-inspector/" rel="noopener noreferrer"&gt;browser-local JWT Inspector&lt;/a&gt; decodes headers and claims and flags risky settings such as &lt;code&gt;alg: none&lt;/code&gt; the same way.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist for your next audit
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Fix ownership before touching permissions, and keep diagnostic data on hardware you control.&lt;/strong&gt; Most &lt;code&gt;Permission denied&lt;/code&gt; errors are UID or group mismatches, not missing bits.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;ls -lan&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; before changing any mode.&lt;/li&gt;
&lt;li&gt;Fix the owner or group with &lt;code&gt;chown&lt;/code&gt;, or set the right runtime user.&lt;/li&gt;
&lt;li&gt;Apply the matrix: 700, 600, 400, 2770, 555 or 000.&lt;/li&gt;
&lt;li&gt;Run the &lt;code&gt;find&lt;/code&gt; audit commands and review every world-writable result.&lt;/li&gt;
&lt;li&gt;Decode logs and tokens locally, then confirm in DevTools that nothing left the tab.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All of the browser utilities mentioned here are collected on &lt;a href="https://localsectools.com/" rel="noopener noreferrer"&gt;LocalSecTools&lt;/a&gt;, a set of client-side tools that run entirely in the browser.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>security</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Stop Pasting Production Secrets Into Web Calculators: Subnet, chmod and Cron Math You Can Do Offline</title>
      <dc:creator>Asad Ali</dc:creator>
      <pubDate>Tue, 03 Nov 2026 19:03:11 +0000</pubDate>
      <link>https://dev.to/asad_ali/stop-pasting-production-secrets-into-web-calculators-subnet-chmod-and-cron-math-you-can-do-offline-1h02</link>
      <guid>https://dev.to/asad_ali/stop-pasting-production-secrets-into-web-calculators-subnet-chmod-and-cron-math-you-can-do-offline-1h02</guid>
      <description>&lt;p&gt;As an IT Support &amp;amp; SecOps engineer, I paste sensitive data into tools all day. A few years ago I watched a teammate drop a live bearer token into a random JWT decoder during an incident. Nobody on that call asked where the token went next, and that question has stayed with me since.&lt;/p&gt;

&lt;p&gt;This post covers that risk first. Then it walks through the math I use most often: small cloud subnets, Linux permission bits, and cron schedules that collide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is pasting production data into web calculators an OpSec risk?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Every server-side calculator receives your input as a request body, and you have no control over what happens to it after that.&lt;/strong&gt; It can land in access logs, WAF logs, APM traces, error trackers, or third-party analytics scripts. You are trusting an unknown retention policy with data your own team would never email in plain text.&lt;/p&gt;

&lt;p&gt;The three worst offenders I see in real incidents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Production JWTs.&lt;/strong&gt; A token stays valid until its &lt;code&gt;exp&lt;/code&gt; claim passes. Anyone who reads it from a log can replay it against your API, and most teams cannot revoke a single JWT.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Obfuscated PowerShell from an incident.&lt;/strong&gt; Those logs contain hostnames, usernames, internal paths and often the attacker's C2 address. Sending them to an unknown server leaks your internal layout and can tip off whoever is watching that infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internal VPC subnet maps.&lt;/strong&gt; A list of CIDR blocks with labels like &lt;code&gt;prod-db&lt;/code&gt; or &lt;code&gt;vpn-pool&lt;/code&gt; is a reconnaissance gift. It tells an attacker exactly where to pivot after the first foothold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fix is simple: use tools that compute in the browser and never send the input anywhere. You can verify this yourself in a minute. Open DevTools, switch to the Network tab, paste your input, and confirm that no request carries it.&lt;/p&gt;

&lt;p&gt;That test is why I built &lt;a href="https://localsectools.com/" rel="noopener noreferrer"&gt;LocalSecTools, a set of browser-only security and sysadmin utilities&lt;/a&gt;. Every calculation there runs in JavaScript on your machine, and the Network tab stays quiet while you work.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do you find the host bits in a 255.255.255.224 mask?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The mask 255.255.255.224 equals /27, so 5 bits identify the host and 30 addresses are usable.&lt;/strong&gt; The answer comes from counting the 1-bits in the mask and subtracting from 32. Here is the full working, step by step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Convert the mask to binary.&lt;/strong&gt; The first three octets are 255, which is eight 1-bits each. Only the last octet needs real work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;255.255.255.224
11111111.11111111.11111111.11100000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Read the last octet.&lt;/strong&gt; The value 224 equals 128 + 64 + 32, so the top three bits are set and the bottom five are zero.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;128  64  32  16   8   4   2   1
  1   1   1   0   0   0   0   0   = 224
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Count network bits.&lt;/strong&gt; That gives 8 + 8 + 8 + 3 = 27 network bits, so the prefix is &lt;code&gt;/27&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Subtract from 32.&lt;/strong&gt; The host portion is whatever remains of the 32-bit address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;host bits      h = 32 - prefix = 32 - 27 = 5
total addrs      = 2^h         = 2^5     = 32
usable (RFC)     = 2^h - 2     = 32 - 2  = 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We subtract two because the first address names the subnet itself and the last one is reserved for broadcast. You can confirm the result from any Linux shell without installing anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"import ipaddress as i; n=i.ip_network('10.20.30.64/27'); print(n.netmask, n.num_addresses, n.num_addresses-2)"&lt;/span&gt;
&lt;span class="c"&gt;# 255.255.255.224 32 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;ipcalc&lt;/code&gt; is installed, &lt;code&gt;ipcalc 10.20.30.64/27&lt;/code&gt; prints the same mask, host range and broadcast address. For a longer walkthrough of each prefix, I wrote up &lt;a href="https://localsectools.com/blog/slash-30-vs-29-28-27-subnet-mask-host-bits-explained/" rel="noopener noreferrer"&gt;the /30 vs /29 vs /28 vs /27 host bits breakdown&lt;/a&gt; with worked examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do /27 to /30 subnets give fewer hosts in AWS and Azure?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AWS and Azure reserve five addresses in every subnet, so the usable count is &lt;code&gt;2^h - 5&lt;/code&gt; instead of &lt;code&gt;2^h - 2&lt;/code&gt;.&lt;/strong&gt; That difference is small on a /24 but painful on tiny subnets. Both clouds also refuse prefixes that are too small to be useful.&lt;/p&gt;

&lt;p&gt;The five reserved addresses follow the same pattern in both clouds. The network address and broadcast address are blocked like on-prem. The cloud also keeps &lt;code&gt;.1&lt;/code&gt; for the router, &lt;code&gt;.2&lt;/code&gt; for DNS, and &lt;code&gt;.3&lt;/code&gt; for future use.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Prefix&lt;/th&gt;
&lt;th&gt;Subnet mask&lt;/th&gt;
&lt;th&gt;Host bits (h)&lt;/th&gt;
&lt;th&gt;Total (&lt;code&gt;2^h&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;RFC usable (&lt;code&gt;2^h - 2&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;AWS / Azure usable (&lt;code&gt;2^h - 5&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Cloud allows it?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;/27&lt;/td&gt;
&lt;td&gt;255.255.255.224&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;td&gt;AWS and Azure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;/28&lt;/td&gt;
&lt;td&gt;255.255.255.240&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;AWS and Azure (smallest on AWS)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;/29&lt;/td&gt;
&lt;td&gt;255.255.255.248&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Azure only (smallest on Azure)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;/30&lt;/td&gt;
&lt;td&gt;255.255.255.252&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;-1 (impossible)&lt;/td&gt;
&lt;td&gt;Neither&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The /30 row is the one that catches people. It is the classic point-to-point mask on physical routers, but in a VPC it leaves negative space. AWS rejects it outright:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 create-subnet &lt;span class="nt"&gt;--vpc-id&lt;/span&gt; vpc-0example &lt;span class="nt"&gt;--cidr-block&lt;/span&gt; 10.20.30.0/30
&lt;span class="c"&gt;# An error occurred (InvalidSubnet.Range) ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My rule for cloud planning: never go below /28 for anything that might scale. Load balancers, NAT gateways and managed endpoints each consume addresses you did not plan for. A /27 with 27 usable addresses costs you nothing extra and saves a painful re-IP later.&lt;/p&gt;

&lt;p&gt;Before I commit a VPC layout, I split the parent block in the &lt;a href="https://localsectools.com/tools/cidr-subnet-splitter/" rel="noopener noreferrer"&gt;CIDR subnet splitter that runs in your browser&lt;/a&gt;. It shows network, broadcast and usable ranges for each child, and my internal ranges never leave the laptop. If you need a refresher on which blocks are safe for internal use, see &lt;a href="https://localsectools.com/blog/private-ip-ranges-rfc-1918-subnet-mask-to-cidr-guide/" rel="noopener noreferrer"&gt;this guide to RFC 1918 private IP ranges and mask-to-CIDR conversion&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does chmod octal math work?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Each octal digit is the sum of three bits: read is 4, write is 2 and execute is 1.&lt;/strong&gt; Reading left to right, the digits cover the file owner, the owning group, and everyone else. So a mode like 750 is really a 9-bit mask.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;value = (r ? 4 : 0) + (w ? 2 : 0) + (x ? 1 : 0)

7 = 111 = rwx      6 = 110 = rw-      5 = 101 = r-x
4 = 100 = r--      0 = 000 = ---

chmod 750  -&amp;gt;  111 101 000  -&amp;gt;  rwx r-x ---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you see the bits, the production modes stop being magic numbers. Each one removes exactly the access a given file type should not have.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;Bits&lt;/th&gt;
&lt;th&gt;Symbolic&lt;/th&gt;
&lt;th&gt;Where I use it&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;600&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;110 000 000&lt;/td&gt;
&lt;td&gt;&lt;code&gt;rw-------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SSH private keys, &lt;code&gt;.env&lt;/code&gt; files&lt;/td&gt;
&lt;td&gt;Owner reads and writes, nobody else sees it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;400&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;100 000 000&lt;/td&gt;
&lt;td&gt;&lt;code&gt;r--------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;AWS &lt;code&gt;.pem&lt;/code&gt; key pairs&lt;/td&gt;
&lt;td&gt;Read-only, even the owner cannot overwrite by accident&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;750&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;111 101 000&lt;/td&gt;
&lt;td&gt;&lt;code&gt;rwxr-x---&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Service directories like &lt;code&gt;/opt/app&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Service group can enter and read, others are locked out&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;555&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;101 101 101&lt;/td&gt;
&lt;td&gt;&lt;code&gt;r-xr-xr-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Shipped binaries and scripts&lt;/td&gt;
&lt;td&gt;Everyone runs it, nobody edits it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;000&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;000 000 000&lt;/td&gt;
&lt;td&gt;&lt;code&gt;---------&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Temporary user-space lockout&lt;/td&gt;
&lt;td&gt;No access until the owner or root restores the mode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;666&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;110 110 110&lt;/td&gt;
&lt;td&gt;&lt;code&gt;rw-rw-rw-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Never on servers&lt;/td&gt;
&lt;td&gt;Any local user can rewrite the file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;777&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;111 111 111&lt;/td&gt;
&lt;td&gt;&lt;code&gt;rwxrwxrwx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Never on servers&lt;/td&gt;
&lt;td&gt;Any local user can replace code that someone else executes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two notes from real tickets. OpenSSH refuses a private key that group or others can read, and prints a loud "UNPROTECTED PRIVATE KEY FILE" warning. The fix is one 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;chmod &lt;/span&gt;600 ~/.ssh/id_ed25519
&lt;span class="nb"&gt;chmod &lt;/span&gt;400 ~/keys/prod-bastion.pem
&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'%a %A %n'&lt;/span&gt; ~/.ssh/id_ed25519   &lt;span class="c"&gt;# 600 -rw------- /home/asad/.ssh/id_ed25519&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, &lt;code&gt;000&lt;/code&gt; and &lt;code&gt;555&lt;/code&gt; are not protection against root. Root bypasses read and write checks, and the file owner can always run &lt;code&gt;chmod&lt;/code&gt; again. Treat these modes as guardrails against mistakes, not as a security boundary.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;666&lt;/code&gt; and &lt;code&gt;777&lt;/code&gt; modes are the ones I hunt for during audits. A world-writable script that a cron job runs as root is a straight path to privilege escalation. This sweep finds them on a single filesystem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find / &lt;span class="nt"&gt;-xdev&lt;/span&gt; &lt;span class="nt"&gt;-type&lt;/span&gt; f &lt;span class="nt"&gt;-perm&lt;/span&gt; &lt;span class="nt"&gt;-0002&lt;/span&gt; &lt;span class="nt"&gt;-ls&lt;/span&gt; 2&amp;gt;/dev/null   &lt;span class="c"&gt;# world-writable files&lt;/span&gt;
find / &lt;span class="nt"&gt;-xdev&lt;/span&gt; &lt;span class="nt"&gt;-type&lt;/span&gt; d &lt;span class="nt"&gt;-perm&lt;/span&gt; &lt;span class="nt"&gt;-0002&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-perm&lt;/span&gt; &lt;span class="nt"&gt;-1000&lt;/span&gt; &lt;span class="nt"&gt;-ls&lt;/span&gt; 2&amp;gt;/dev/null   &lt;span class="c"&gt;# world-writable dirs without sticky bit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I need to translate between octal and symbolic quickly, I use this &lt;a href="https://localsectools.com/tools/chmod-calculator/" rel="noopener noreferrer"&gt;client-side chmod calculator with octal and symbolic sync&lt;/a&gt;. For a deeper look at each mode, read &lt;a href="https://localsectools.com/blog/chmod-000-400-555-600-666-770-linux-permissions-guide/" rel="noopener noreferrer"&gt;my breakdown of restrictive Linux file modes from 000 to 770&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why replace overlapping crontabs with systemd timers?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cron starts a new copy of a job on schedule, even if the previous run is still going, while a systemd service will not start twice while it is active.&lt;/strong&gt; That single difference removes a whole class of overlap bugs. It matters most when two schedules land on the same minute.&lt;/p&gt;

&lt;p&gt;Take two common entries on one host:&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="k"&gt;*&lt;/span&gt;/5 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;  /usr/local/bin/sync-inventory.sh
0 &lt;span class="k"&gt;*&lt;/span&gt;/4 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;  /usr/local/bin/full-backup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At 00:00, 04:00, 08:00 and every fourth hour, both fire in the same minute. If the backup locks the same database the sync job reads, the sync stretches past five minutes. Cron then launches another sync on top of it, and the pile-up grows until something times out.&lt;/p&gt;

&lt;p&gt;The quick fix keeps cron and adds a non-blocking lock. With &lt;code&gt;flock -n&lt;/code&gt;, a second copy exits right away instead of queuing:&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="k"&gt;*&lt;/span&gt;/5 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;  flock &lt;span class="nt"&gt;-n&lt;/span&gt; /run/lock/sync-inventory.lock /usr/local/bin/sync-inventory.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The better fix moves the job to a systemd timer. The timer only triggers the service, and systemd skips the trigger if the service is still active. You also get journald logs and a clear view of the next run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c"&gt;# /etc/systemd/system/sync-inventory.timer
&lt;/span&gt;&lt;span class="nn"&gt;[Unit]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="py"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;Inventory sync every 5 minutes&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nn"&gt;[Timer]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="py"&gt;OnCalendar&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;*:0/5&lt;/span&gt;
&lt;span class="py"&gt;Persistent&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;
&lt;span class="py"&gt;RandomizedDelaySec&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;30&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nn"&gt;[Install]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="py"&gt;WantedBy&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;timers.target&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;systemd-analyze calendar &lt;span class="s1"&gt;'*:0/5'&lt;/span&gt;          &lt;span class="c"&gt;# preview the next trigger time&lt;/span&gt;
systemd-analyze calendar &lt;span class="s1"&gt;'00/4:00'&lt;/span&gt;        &lt;span class="c"&gt;# the 0 */4 * * * equivalent&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;--now&lt;/span&gt; sync-inventory.timer
systemctl list-timers sync-inventory.timer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;RandomizedDelaySec&lt;/code&gt; line spreads the start by up to 30 seconds, which also breaks the exact-minute collision with the backup. &lt;code&gt;Persistent=true&lt;/code&gt; runs a missed trigger after a reboot, which plain cron never does.&lt;/p&gt;

&lt;p&gt;Converting cron syntax to &lt;code&gt;OnCalendar&lt;/code&gt; by hand is where I make mistakes. Weekday ranges and day-of-month rules differ in subtle ways. I paste the expression into this &lt;a href="https://localsectools.com/tools/cron-visualizer/" rel="noopener noreferrer"&gt;cron visualizer that previews next runs and outputs systemd OnCalendar units&lt;/a&gt;, then copy the generated &lt;code&gt;.timer&lt;/code&gt; and &lt;code&gt;.service&lt;/code&gt; pair.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should you check before trusting any online security tool?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Check whether your input leaves the browser, and assume anything that does is stored somewhere.&lt;/strong&gt; The DevTools Network tab answers that in seconds. If the tool still works with Wi-Fi turned off, the math happens locally.&lt;/p&gt;

&lt;p&gt;My short checklist before I paste anything sensitive:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open DevTools, then the Network tab, and clear it.&lt;/li&gt;
&lt;li&gt;Paste the input and run the tool.&lt;/li&gt;
&lt;li&gt;Look for any POST or fetch request that contains your data.&lt;/li&gt;
&lt;li&gt;If in doubt, disconnect from the network and run it again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of the math in this post needs a server. Subnet masks are bit shifts, chmod is addition, and cron parsing is string matching. Keeping that work local is the easiest OpSec win I know.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Asad Ali is an IT Support &amp;amp; SecOps engineer, Microsoft SC-200 and ISC2 CC certified. You can find more of my work at &lt;a href="https://asadali.tech/" rel="noopener noreferrer"&gt;asadali.tech&lt;/a&gt;. If this post saved you a re-IP or a 3 a.m. cron pile-up, try the &lt;a href="https://localsectools.com/" rel="noopener noreferrer"&gt;10 client-side utilities on LocalSecTools&lt;/a&gt;, from JWT inspection to log deobfuscation, and tell me which tool you want next.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>devops</category>
      <category>linux</category>
      <category>networking</category>
    </item>
  </channel>
</rss>
