<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Tips on Kiril Vladimirov</title>
    <link>https://vld.bg/tips/</link>
    <description>Recent content in Tips on Kiril Vladimirov</description>
    <generator>Hugo -- 0.168.0</generator>
    <language>en</language>
    <atom:link href="https://vld.bg/tips/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>~/.sqliterc</title>
      <link>https://vld.bg/tips/sqliterc/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/sqliterc/</guid>
      <description>&lt;p&gt;TL;DR: &lt;code&gt;echo &#39;.mode box&#39; &amp;gt; ~/.sqliterc&lt;/code&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;SQLite is a great database (although often overlooked) with a bit of annoying CLI defaults.&lt;/p&gt;
&lt;p&gt;For instance:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sqlite&amp;gt; select * from Album limit 10;
1|For Those About To Rock We Salute You|1
2|Balls to the Wall|2
3|Restless and Wild|2
4|Let There Be Rock|1
5|Big Ones|3
6|Jagged Little Pill|4
7|Facelift|5
8|Warner 25 Anos|6
9|Plays Metallica By Four Cellos|7
10|Audioslave|8
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Three columns, two of them are numbers, and yet things are hard to read. Write
&lt;code&gt;.mode box&lt;/code&gt; in your &lt;code&gt;~/.sqliterc&lt;/code&gt; and things change dramatically:&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>TL;DR: <code>echo '.mode box' &gt; ~/.sqliterc</code></p>
<hr>
<p>SQLite is a great database (although often overlooked) with a bit of annoying CLI defaults.</p>
<p>For instance:</p>
<pre tabindex="0"><code>sqlite&gt; select * from Album limit 10;
1|For Those About To Rock We Salute You|1
2|Balls to the Wall|2
3|Restless and Wild|2
4|Let There Be Rock|1
5|Big Ones|3
6|Jagged Little Pill|4
7|Facelift|5
8|Warner 25 Anos|6
9|Plays Metallica By Four Cellos|7
10|Audioslave|8
</code></pre><p>Three columns, two of them are numbers, and yet things are hard to read. Write
<code>.mode box</code> in your <code>~/.sqliterc</code> and things change dramatically:</p>
<pre tabindex="0"><code>sqlite&gt; select * from Album limit 10;
┌─────────┬───────────────────────────────────────┬──────────┐
│ AlbumId │                 Title                 │ ArtistId │
├─────────┼───────────────────────────────────────┼──────────┤
│ 1       │ For Those About To Rock We Salute You │ 1        │
│ 2       │ Balls to the Wall                     │ 2        │
│ 3       │ Restless and Wild                     │ 2        │
│ 4       │ Let There Be Rock                     │ 1        │
│ 5       │ Big Ones                              │ 3        │
│ 6       │ Jagged Little Pill                    │ 4        │
│ 7       │ Facelift                              │ 5        │
│ 8       │ Warner 25 Anos                        │ 6        │
│ 9       │ Plays Metallica By Four Cellos        │ 7        │
│ 10      │ Audioslave                            │ 8        │
└─────────┴───────────────────────────────────────┴──────────┘
</code></pre>]]></content:encoded>
    </item>
    <item>
      <title>Authorize SSH keys</title>
      <link>https://vld.bg/tips/ssh-keys/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/ssh-keys/</guid>
      <description>&lt;p&gt;How often have you asked or have been asked to provide public SSH keys in order
to get authorized into given server or Git repository? I&amp;rsquo;ve heard horror
stories of people providing private keys, by mistake. GitHub and GitLab ease
this process greatly, but are not advertising it well enough.&lt;/p&gt;
&lt;p&gt;You can append &lt;code&gt;.keys&lt;/code&gt; to the URL of your profile in order to receive the
public keys you have on your account in a format to directly pipe it into
&lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt;:&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>How often have you asked or have been asked to provide public SSH keys in order
to get authorized into given server or Git repository? I&rsquo;ve heard horror
stories of people providing private keys, by mistake. GitHub and GitLab ease
this process greatly, but are not advertising it well enough.</p>
<p>You can append <code>.keys</code> to the URL of your profile in order to receive the
public keys you have on your account in a format to directly pipe it into
<code>~/.ssh/authorized_keys</code>:</p>
<pre tabindex="0"><code>curl https://github.com/&lt;username&gt;.keys | tee -a ~/.ssh/authorized_keys
</code></pre><p>Same goes for any GitLab instance.</p>
]]></content:encoded>
    </item>
    <item>
      <title>find tricks</title>
      <link>https://vld.bg/tips/find/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/find/</guid>
      <description>&lt;p&gt;Tasks I tend to forget how to perform with
&lt;a href=&#34;https://linux.die.net/man/1/find&#34; target=&#34;_blank&#34;&gt;find(1)&lt;/a&gt;
.&lt;/p&gt;
&lt;h2 id=&#34;delete-matched-files&#34;&gt;Delete matched files&lt;/h2&gt;
&lt;p&gt;The most trivial one: &lt;code&gt;find &amp;lt;path&amp;gt; [..] -delete&lt;/code&gt; (e.g. &lt;code&gt;find . -name foo -delete&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;However, depending on the OS &lt;code&gt;-delete&lt;/code&gt; might not be available. In that case,
see the next one.&lt;/p&gt;
&lt;h2 id=&#34;execute-command-with-matched-files&#34;&gt;Execute command with matched files&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;find &amp;lt;path&amp;gt; [..]  -exec &amp;lt;cmd&amp;gt; &#39;{}&#39; \;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;cmd&gt; is executed once for each matched file and the relative path to it is
replaces &lt;code&gt;&#39;{}&#39;&lt;/code&gt; and I always forget that &lt;code&gt;\;&lt;/code&gt;, which might be omitted depending
on a bunch of weird shell-isms
(e.g. &lt;code&gt;find . -name foo -exec rm -f &#39;{}&#39; \;&lt;/code&gt;).&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Tasks I tend to forget how to perform with
<a href="https://linux.die.net/man/1/find" target="_blank">find(1)</a>
.</p>
<h2 id="delete-matched-files">Delete matched files</h2>
<p>The most trivial one: <code>find &lt;path&gt; [..] -delete</code> (e.g. <code>find . -name foo -delete</code>).</p>
<p>However, depending on the OS <code>-delete</code> might not be available. In that case,
see the next one.</p>
<h2 id="execute-command-with-matched-files">Execute command with matched files</h2>
<pre><code>find &lt;path&gt; [..]  -exec &lt;cmd&gt; '{}' \;
</code></pre>
<p><cmd> is executed once for each matched file and the relative path to it is
replaces <code>'{}'</code> and I always forget that <code>\;</code>, which might be omitted depending
on a bunch of weird shell-isms
(e.g. <code>find . -name foo -exec rm -f '{}' \;</code>).</p>
<p>If you want to call <code>&lt;cmd&gt;</code> exactly once (with caveats) with all the matched
files passed as argument, add <code>+</code> at the end, but then <code>'{}'</code> should be right
at the end of the command just before the <code>+</code>:
<code>find . -type f -name 'foo*' -exec rm -f '{}' +</code></p>
<h2 id="match-files-by-modification-time">Match files by modification time</h2>
<pre><code>find &lt;path&gt; [..] -mtime [+-]n
</code></pre>
<ul>
<li>
<p>n means modified <strong>precisely</strong> n days ago. This matches all files modified
a week ago:<br><code>find . -mtime 7</code></p>
</li>
<li>
<p>+n means modified <strong>at least</strong> n days ago. This matches all files older than
a week:<br><code>find . -mtime +7</code></p>
</li>
<li>
<p>-n means modified <strong>within the last</strong> n days. This matches all files older than
a week:<br><code>find . -mtime -7</code></p>
</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>Generate password</title>
      <link>https://vld.bg/tips/passwd/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/passwd/</guid>
      <description>&lt;h2 id=&#34;pwgen-length-count&#34;&gt;pwgen [length] [count]&lt;/h2&gt;
&lt;p&gt;By default it generates a bunch of passwords in columns. However with args it
can be ustructed to generate one fairly long secret (64 characters):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pwgen 64 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It has fairly good number of ways to configure what and how exactly to
generate. The downside of this approach is that
&lt;a href=&#34;https://linux.die.net/man/1/pwgen&#34; target=&#34;_blank&#34;&gt;pwgen(1)&lt;/a&gt;
 is probably not installed by
default on your machine.&lt;/p&gt;
&lt;h2 id=&#34;devurandom&#34;&gt;/dev/urandom&lt;/h2&gt;
&lt;p&gt;Reading directly from /dev/urandom is the way to go on pretty much any UNIX
these days (or fallback to /dev/random, although both are the same except on
Linux) without having to install anything. The only question is how to make it
output plain-text.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<h2 id="pwgen-length-count">pwgen [length] [count]</h2>
<p>By default it generates a bunch of passwords in columns. However with args it
can be ustructed to generate one fairly long secret (64 characters):</p>
<pre><code>pwgen 64 1
</code></pre>
<p>It has fairly good number of ways to configure what and how exactly to
generate. The downside of this approach is that
<a href="https://linux.die.net/man/1/pwgen" target="_blank">pwgen(1)</a>
 is probably not installed by
default on your machine.</p>
<h2 id="devurandom">/dev/urandom</h2>
<p>Reading directly from /dev/urandom is the way to go on pretty much any UNIX
these days (or fallback to /dev/random, although both are the same except on
Linux) without having to install anything. The only question is how to make it
output plain-text.</p>
<h3 id="base641"><a href="https://linux.die.net/man/1/base64" target="_blank">base64(1)</a>
</h3>
<p>Arguably the easiest way if you don&rsquo;t care that the only possible &ldquo;special&rdquo;
characters besides letters and numbers are + and /:</p>
<pre><code>base64 /dev/urandom | head -c64
</code></pre>
<h3 id="tr1"><a href="https://linux.die.net/man/1/tr" target="_blank">tr(1)</a>
</h3>
<p>If you need to define a strict alphabet to use for your secret:</p>
<pre><code>cat /dev/urandom | tr -dc 'a-zA-Z0-9_!@#$%^&amp;*()~+=-' | head -c64
</code></pre>
<h3 id="openssl1"><a href="https://linux.die.net/man/1/openssl" target="_blank">openssl(1)</a>
</h3>
<p>OpenSSL can also do the job with two possible outputs:</p>
<ul>
<li>
<p>hex: <code>openssl rand -hex 42</code></p>
</li>
<li>
<p>base64: <code>openssl rand -base64 42</code> (uses = paddings)</p>
</li>
</ul>
<p>The numeric argument is not characters, though.</p>
<h3 id="gpg1"><a href="https://linux.die.net/man/1/gpg" target="_blank">gpg(1)</a>
</h3>
<p>Because obviously GPG can do everything security related:</p>
<pre><code>gpg --gen-random --armor 1 42
</code></pre>
<p>First number is &ldquo;quality level&rdquo; which is&hellip; complicated as with anything
related to GPG anyways.</p>
]]></content:encoded>
    </item>
    <item>
      <title>git bisect</title>
      <link>https://vld.bg/tips/git-bisect/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/git-bisect/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://git-scm.com/docs/git-bisect&#34; target=&#34;_blank&#34;&gt;git bisect&lt;/a&gt;
 provides easy to use binary
search approach in order to find a bad commit. This tip assumes you know how it
works is in general, but always forget what the commands are precisely.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Prepare a single command that tries to reproduce the bug (e.g. script,
test) &lt;strong&gt;off tree&lt;/strong&gt;. Bisect is about to start jumping around, so it can&amp;rsquo;t be
in the tree.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git bisect start&lt;/code&gt;: begin the bisect session.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git bisect bad&lt;/code&gt;: mark current HEAD as a bad commit (i.e. the bug is
reproducible).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git bisect good &amp;lt;commit-ref&amp;gt;&lt;/code&gt;: some known commit in the past, where the bug
does not exist.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You get dropped at a given commit. Try the command/test/script from step 1
and:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;if the bug exists: &lt;code&gt;git bisect bad&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;if the bug does NOT exist: &lt;code&gt;git bisect good&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Repeat until the initial bad commit is found.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git bisect reset&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</description>
      <content:encoded><![CDATA[<p><a href="https://git-scm.com/docs/git-bisect" target="_blank">git bisect</a>
 provides easy to use binary
search approach in order to find a bad commit. This tip assumes you know how it
works is in general, but always forget what the commands are precisely.</p>
<ol>
<li>
<p>Prepare a single command that tries to reproduce the bug (e.g. script,
test) <strong>off tree</strong>. Bisect is about to start jumping around, so it can&rsquo;t be
in the tree.</p>
</li>
<li>
<p><code>git bisect start</code>: begin the bisect session.</p>
</li>
<li>
<p><code>git bisect bad</code>: mark current HEAD as a bad commit (i.e. the bug is
reproducible).</p>
</li>
<li>
<p><code>git bisect good &lt;commit-ref&gt;</code>: some known commit in the past, where the bug
does not exist.</p>
</li>
<li>
<p>You get dropped at a given commit. Try the command/test/script from step 1
and:</p>
<ul>
<li>if the bug exists: <code>git bisect bad</code></li>
<li>if the bug does NOT exist: <code>git bisect good</code></li>
</ul>
</li>
<li>
<p>Repeat until the initial bad commit is found.</p>
</li>
<li>
<p><code>git bisect reset</code>.</p>
</li>
</ol>
<h2 id="git-bisect-run">git bisect run</h2>
<p>Steps 5 and 6 can be automated with <code>git bisect run</code> if you can provide a
script that exits with status code 0 when the chosen revision is good and
something between 1 and 127 (except for 125) when the revision is bad.</p>
<p>The script should obviously be out of tree and executed with:</p>
<p><code>git bisect run &lt;script_name&gt; [&lt;arg&gt; ...]</code>.</p>
]]></content:encoded>
    </item>
    <item>
      <title>nmap</title>
      <link>https://vld.bg/tips/nmap/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/nmap/</guid>
      <description>&lt;h2 id=&#34;find-hosts-in-a-range&#34;&gt;Find hosts in a range&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;nmap -sn 1.2.3.0/24
&lt;/code&gt;&lt;/pre&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;HOST DISCOVERY:
-sL: List Scan - simply list targets to scan
-sn: Ping Scan - disable port scan
-Pn: Treat all hosts as online -- skip host discovery
-PS/PA/PU/PY[portlist]: TCP SYN, TCP ACK, UDP or SCTP discovery to given ports
-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
-PO[protocol list]: IP Protocol Ping
-n/-R: Never do DNS resolution/Always resolve [default: sometimes]
--dns-servers &amp;lt;serv1[,serv2],...&amp;gt;: Specify custom DNS servers
--system-dns: Use OS&amp;#39;s DNS resolver
--traceroute: Trace hop path to each host
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;port-scanning&#34;&gt;Port Scanning&lt;/h2&gt;
&lt;p&gt;Quick TCP SYN scanning (&lt;code&gt;-sS&lt;/code&gt;: requires root), skipping host discovery (&lt;code&gt;-Pn&lt;/code&gt;),
of most popular ports:&lt;/p&gt;</description>
      <content:encoded><![CDATA[<h2 id="find-hosts-in-a-range">Find hosts in a range</h2>
<pre><code>nmap -sn 1.2.3.0/24
</code></pre>
<pre tabindex="0"><code>HOST DISCOVERY:
-sL: List Scan - simply list targets to scan
-sn: Ping Scan - disable port scan
-Pn: Treat all hosts as online -- skip host discovery
-PS/PA/PU/PY[portlist]: TCP SYN, TCP ACK, UDP or SCTP discovery to given ports
-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
-PO[protocol list]: IP Protocol Ping
-n/-R: Never do DNS resolution/Always resolve [default: sometimes]
--dns-servers &lt;serv1[,serv2],...&gt;: Specify custom DNS servers
--system-dns: Use OS&#39;s DNS resolver
--traceroute: Trace hop path to each host
</code></pre><h2 id="port-scanning">Port Scanning</h2>
<p>Quick TCP SYN scanning (<code>-sS</code>: requires root), skipping host discovery (<code>-Pn</code>),
of most popular ports:</p>
<pre><code>nmap -sS -Pn 1.2.3.4
</code></pre>
<p>Port ranges can be given with <code>-p100-1000</code> (from :100 to :1000). All ports is
<code>-p-</code>. Single port is also accepted: <code>-p 22</code></p>
<p>UDP Scanning:</p>
<pre><code>nmap -sU -Pn 1.2.3.4
</code></pre>
<pre tabindex="0"><code>SCAN TECHNIQUES:
 -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
 -sU: UDP Scan
 -sN/sF/sX: TCP Null, FIN, and Xmas scans
 --scanflags &lt;flags&gt;: Customize TCP scan flags
 -sI &lt;zombie host[:probeport]&gt;: Idle scan
 -sY/sZ: SCTP INIT/COOKIE-ECHO scans
 -sO: IP protocol scan
 -b &lt;FTP relay host&gt;: FTP bounce scan

PORT SPECIFICATION AND SCAN ORDER:
 -p &lt;port ranges&gt;: Only scan specified ports
   Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
 --exclude-ports &lt;port ranges&gt;: Exclude the specified ports from scanning
 -F: Fast mode - Scan fewer ports than the default scan
 -r: Scan ports sequentially - don&#39;t randomize
 --top-ports &lt;number&gt;: Scan &lt;number&gt; most common ports
 --port-ratio &lt;ratio&gt;: Scan ports more common than &lt;ratio&gt;
</code></pre><h2 id="misc">Misc:</h2>
<ul>
<li>OS discover: <code>-O</code> (uppercase <code>o</code>, not a zero)</li>
<li>Application discovery: <code>-sV</code></li>
<li>Everything: <code>-A</code> (traceroute, app discovery, OS detecetion, port scanning&hellip;)</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>rsync</title>
      <link>https://vld.bg/tips/rsync/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/rsync/</guid>
      <description>&lt;pre&gt;&lt;code&gt;rsync -arvzh [host:]/source/path/ [host:]/destination/path
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the trailing slash in source path: this avoids creating &lt;code&gt;[host:]/destination/path/path&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-a&lt;/code&gt;: archive (i.e. ensures that symlinks, attributes, permissions, owner, etc. are preserved)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-r&lt;/code&gt;: recursive&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-v&lt;/code&gt;: verbose (second &lt;code&gt;v&lt;/code&gt; gives what files are being skipped and some stats at the end)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-z&lt;/code&gt;: compress&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-h&lt;/code&gt;: human-readable format of numbers&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--del | --delete&lt;/code&gt;: delete files on the destination that are not sent from
the source&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--stats&lt;/code&gt;: file-transfer statistics at the end&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-m&lt;/code&gt;: prune empty directories from file-list&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-t&lt;/code&gt;: preserve modification times&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
      <content:encoded><![CDATA[<pre><code>rsync -arvzh [host:]/source/path/ [host:]/destination/path
</code></pre>
<p>Note the trailing slash in source path: this avoids creating <code>[host:]/destination/path/path</code>.</p>
<ul>
<li><code>-a</code>: archive (i.e. ensures that symlinks, attributes, permissions, owner, etc. are preserved)</li>
<li><code>-r</code>: recursive</li>
<li><code>-v</code>: verbose (second <code>v</code> gives what files are being skipped and some stats at the end)</li>
<li><code>-z</code>: compress</li>
<li><code>-h</code>: human-readable format of numbers</li>
</ul>
<hr>
<ul>
<li>
<p><code>--del | --delete</code>: delete files on the destination that are not sent from
the source</p>
</li>
<li>
<p><code>--stats</code>: file-transfer statistics at the end</p>
</li>
<li>
<p><code>-m</code>: prune empty directories from file-list</p>
</li>
<li>
<p><code>-t</code>: preserve modification times</p>
</li>
</ul>
<hr>
<p>This is how I deploy changes of this site with rsync:</p>
<pre><code>rsync -arvzh --delete public/ vld.bg:www/vld.bg/public_html/ 
</code></pre>
]]></content:encoded>
    </item>
    <item>
      <title>SSH into an ancient machine</title>
      <link>https://vld.bg/tips/anctient-ssh/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/anctient-ssh/</guid>
      <description>&lt;p&gt;TL;DR: &lt;code&gt;ssh -oHostKeyAlgorithms=+ssh-rsa -oRequiredRSASize=1024 &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Have you ever tried to SSH into an old machine, say a managed switch, UPS or
router from the previous decade only to get declined with the following error:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#d0d0d0;background-color:#202020;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-txt&#34; data-lang=&#34;txt&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Unable to negotiate with &amp;lt;host&amp;gt;: no matching host key type found.
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Their offer: ssh-rsa,ssh-dss
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It&amp;rsquo;s frustrating, isn&amp;rsquo;t it?  OpenSSH implements all of the cryptographic
algorithms needed for compatibility with standards-compliant SSH
implementations, but since some of the older algorithms have been found to be
weak, not all of them are enabled by default. If you want to learn more about
it, definitely should read
&lt;a href=&#34;https://www.openssh.com/legacy.html&#34; target=&#34;_blank&#34;&gt;OpenSSH Legacy Options&lt;/a&gt;
.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>TL;DR: <code>ssh -oHostKeyAlgorithms=+ssh-rsa -oRequiredRSASize=1024 &lt;user&gt;@&lt;host&gt;</code></p>
<p>Have you ever tried to SSH into an old machine, say a managed switch, UPS or
router from the previous decade only to get declined with the following error:</p>
<div class="highlight"><pre tabindex="0" style="color:#d0d0d0;background-color:#202020;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>Unable to negotiate with &lt;host&gt;: no matching host key type found.
</span></span><span style="display:flex;"><span>Their offer: ssh-rsa,ssh-dss
</span></span></code></pre></div><p>It&rsquo;s frustrating, isn&rsquo;t it?  OpenSSH implements all of the cryptographic
algorithms needed for compatibility with standards-compliant SSH
implementations, but since some of the older algorithms have been found to be
weak, not all of them are enabled by default. If you want to learn more about
it, definitely should read
<a href="https://www.openssh.com/legacy.html" target="_blank">OpenSSH Legacy Options</a>
.</p>
<p>But this is a tip, so the short story is that you should use one of offered
algorithms by the server, say <code>-oHostKeyAlgorithms=+ssh-rsa</code>. When it comes to
ssh-rsa, however that won&rsquo;t be enough and you would be challenged with another
error:</p>
<div class="highlight"><pre tabindex="0" style="color:#d0d0d0;background-color:#202020;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>Bad server host key: Invalid key length
</span></span></code></pre></div><p>The crypto-policy that comes with modern distributions does not allow RSA key
sizes &lt; 2048 bit. Some SSH servers are configured with 1024-bit key sizes that
can lead to connection failures. <code>-oRequiredRSASize=1024</code> overrides that
default and Voilà.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Watch for file changes</title>
      <link>https://vld.bg/tips/inotify/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/inotify/</guid>
      <description>&lt;p&gt;TL;DR: &lt;code&gt;inotifywait -m -e close_write -e delete -e move $(pwd)&lt;/code&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Example output under different conditions:&lt;/p&gt;
&lt;h3 id=&#34;touch-foo--echo---foo&#34;&gt;&lt;code&gt;touch foo&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;echo ... &amp;gt; foo&lt;/code&gt;&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;mv-foo-bar&#34;&gt;&lt;code&gt;mv foo bar&lt;/code&gt;&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/path/to/watched/dir/ MOVED_FROM foo
/path/to/watched/dir/ MOVED_TO bar
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;rm-bar&#34;&gt;&lt;code&gt;rm bar&lt;/code&gt;&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/path/to/watched/dir/ DELETE bar
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;text-editors&#34;&gt;Text editors&lt;/h2&gt;
&lt;p&gt;This is where things get interesting&lt;/p&gt;
&lt;h3 id=&#34;vim&#34;&gt;vim&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Boring, right? However, let&amp;rsquo;s do &lt;code&gt;:set backup&lt;/code&gt; and try again:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/path/to/watched/dir/ CLOSE_WRITE,CLOSE 4913
/path/to/watched/dir/ DELETE 4913
/path/to/watched/dir/ MOVED_FROM foo
/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href=&#34;https://vld.bg/articles/4913_123/&#34;&gt;wut?&lt;/a&gt;
&lt;/p&gt;
&lt;h3 id=&#34;emacs&#34;&gt;emacs&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
/path/to/watched/dir/ DELETE .#foo
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;.#foo&lt;/code&gt; is never created, yet deleted.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>TL;DR: <code>inotifywait -m -e close_write -e delete -e move $(pwd)</code></p>
<hr>
<p>Example output under different conditions:</p>
<h3 id="touch-foo--echo---foo"><code>touch foo</code> &amp;&amp; <code>echo ... &gt; foo</code></h3>
<pre tabindex="0"><code>/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
</code></pre><h3 id="mv-foo-bar"><code>mv foo bar</code></h3>
<pre tabindex="0"><code>/path/to/watched/dir/ MOVED_FROM foo
/path/to/watched/dir/ MOVED_TO bar
</code></pre><h3 id="rm-bar"><code>rm bar</code></h3>
<pre tabindex="0"><code>/path/to/watched/dir/ DELETE bar
</code></pre><h2 id="text-editors">Text editors</h2>
<p>This is where things get interesting</p>
<h3 id="vim">vim</h3>
<pre tabindex="0"><code>/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
</code></pre><p>Boring, right? However, let&rsquo;s do <code>:set backup</code> and try again:</p>
<pre tabindex="0"><code>/path/to/watched/dir/ CLOSE_WRITE,CLOSE 4913
/path/to/watched/dir/ DELETE 4913
/path/to/watched/dir/ MOVED_FROM foo
/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
</code></pre><p><a href="/articles/4913_123/">wut?</a>
</p>
<h3 id="emacs">emacs</h3>
<pre tabindex="0"><code>/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
/path/to/watched/dir/ DELETE .#foo
</code></pre><p><code>.#foo</code> is never created, yet deleted.</p>
<h3 id="vscode">vscode</h3>
<pre tabindex="0"><code>/path/to/watched/dir/ CLOSE_WRITE,CLOSE asdf
/path/to/watched/dir/ CLOSE_WRITE,CLOSE asdf
</code></pre><p>Not sure why it does it twice.</p>
]]></content:encoded>
    </item>
    <item>
      <title>What is my IP?</title>
      <link>https://vld.bg/tips/ip/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://vld.bg/tips/ip/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m using a page setup by Jason A. Donenfeld, which he uses to illustrate
&lt;a href=&#34;https://www.wireguard.com/quickstart/&#34; target=&#34;_blank&#34;&gt;setting up WireGuard&lt;/a&gt;
:
&lt;a href=&#34;https://zx2c4.com/ip&#34; target=&#34;_blank&#34;&gt;https://zx2c4.com/ip&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;Even have it as an alias in my
&lt;a href=&#34;https://github.com/vladimiroff/dotfiles&#34; target=&#34;_blank&#34;&gt;dotfiles&lt;/a&gt;
:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;alias myip=&#39;curl -s https://zx2c4.com/ip | head -n1&#39;
&lt;/code&gt;&lt;/pre&gt;</description>
      <content:encoded><![CDATA[<p>I&rsquo;m using a page setup by Jason A. Donenfeld, which he uses to illustrate
<a href="https://www.wireguard.com/quickstart/" target="_blank">setting up WireGuard</a>
:
<a href="https://zx2c4.com/ip" target="_blank">https://zx2c4.com/ip</a>
</p>
<p>Even have it as an alias in my
<a href="https://github.com/vladimiroff/dotfiles" target="_blank">dotfiles</a>
:</p>
<pre><code>alias myip='curl -s https://zx2c4.com/ip | head -n1'
</code></pre>
]]></content:encoded>
    </item>
  </channel>
</rss>
