<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bits on Humberto Rocha</title><link>https://humberto.io/bits/</link><description>Recent content in Bits on Humberto Rocha</description><generator>Hugo</generator><language>en</language><atom:link href="https://humberto.io/bits/index.xml" rel="self" type="application/rss+xml"/><item><title>Setup ssh keys for remote access</title><link>https://humberto.io/bits/setup-ssh-public-keys/</link><pubDate>Mon, 23 Mar 2026 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/setup-ssh-public-keys/</guid><description>&lt;p>To easily setup your public keys into freshly created servers, specially when copy and paste is limited like in proxmox web console you can benefit for one of your accounts in a public or private git servers reachable by your server like Forgejo, Github, and Gitlab.&lt;/p>
&lt;p>They all have the same API where you can fetch your public keys under the pattern:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>https://&amp;lt;git-server&amp;gt;/&amp;lt;username&amp;gt;.keys
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Try it in your browser to see the output.&lt;/p></description></item><item><title>Extract certificate from a domain</title><link>https://humberto.io/bits/extract-certificate-from-a-domain/</link><pubDate>Sun, 06 Jul 2025 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/extract-certificate-from-a-domain/</guid><description>&lt;p>To extract the certificate use:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>openssl s_client -showcerts -servername humberto.io -connect humberto.io:443 &amp;lt;/dev/null 2&amp;gt;/dev/null
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If your target is not using &lt;a href="https://en.wikipedia.org/wiki/Server_Name_Indication">SNI&lt;/a> you don&amp;rsquo;t need to use the &lt;code>-servername &amp;lt;fqdn&amp;gt;&lt;/code> option.&lt;/p>
&lt;p>Then you can pipe it with other OpenSSL commands to extract information in the format that you need.&lt;/p>
&lt;p>To extract PEM formatted cert:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>| openssl x509 -outform PEM
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>To extract the public key:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>| openssl x509 -pubkey -noout
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>To extract the Fingerprint:&lt;/p></description></item><item><title>Extract certificate and key from .pfx file</title><link>https://humberto.io/bits/extract-certificate-and-key-from-pfx-file/</link><pubDate>Mon, 10 Jul 2023 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/extract-certificate-and-key-from-pfx-file/</guid><description>&lt;p>Extract the certificate from the &lt;code>.pfx&lt;/code> file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>openssl pkcs12 -in &amp;lt;DOT_PFX_FILE&amp;gt; -clcerts -nokeys -chain -out certificate.crt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Extract the private key in &lt;code>.pem&lt;/code> format without encryption from the &lt;code>.pfx&lt;/code> file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>openssl pkcs12 -in &amp;lt;DOT_PFX_FILE&amp;gt; -nocerts -nodes -out private_key.pem
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Convert the &lt;code>.pem&lt;/code> into &lt;code>RSA&lt;/code> key format:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>openssl rsa -in private_key.pem -out id_rsa
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If you are using OpenSSL 3 it will default it&amp;rsquo;s output to be in &lt;code>PKCS8&lt;/code> format, that contains encapsulation boundaries like this:&lt;/p></description></item><item><title>Connect to a Kubernetes Pod</title><link>https://humberto.io/bits/connect-to-a-kubernetes-pod/</link><pubDate>Wed, 07 Dec 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/connect-to-a-kubernetes-pod/</guid><description>&lt;p>To open a session it&amp;rsquo;s first required to know the Pod&amp;rsquo;s name.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>kubectl get pod -n &amp;lt;namespace&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then open a bash session by running:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>kubectl exec --stdin --tty &amp;lt;pod name&amp;gt; -n &amp;lt;namespace&amp;gt; -- /bin/bash
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>It&amp;rsquo;s also possible to open a shell session:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>kubectl exec --stdin --tty &amp;lt;pod name&amp;gt; -n &amp;lt;namespace&amp;gt; -- /bin/sh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Sometimes it&amp;rsquo;s need to spawn a new Pod from an image that has the required tooling to inspect something.&lt;/p></description></item><item><title>Interactive session in a Docker container</title><link>https://humberto.io/bits/interactive-session-in-a-docker-container/</link><pubDate>Tue, 22 Nov 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/interactive-session-in-a-docker-container/</guid><description>&lt;p>Opening a bash session in a given container:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>docker exec -it &amp;lt;container-name&amp;gt; /bin/bash
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>In case the image is more bare bones you can still open a shell session:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>docker exec -it &amp;lt;container-name&amp;gt; /bin/sh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;aside class="tip warning">
 You can only open sessions in containers that are running so check their status with &lt;code>docker ps&lt;/code> before trying to open the session.
&lt;/aside>

&lt;p>If you are not sure about the container names you can list them with:&lt;/p></description></item><item><title>Docker without root</title><link>https://humberto.io/bits/docker-without-root/</link><pubDate>Sat, 30 Jul 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/docker-without-root/</guid><description>&lt;p>Create the &lt;code>docker&lt;/code> group.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>sudo groupadd docker
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Add your user to the &lt;code>docker&lt;/code> group.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>sudo usermod -aG docker $USER
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Apply the changes to the group.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>newgrp docker
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Verify if you can run &lt;code>docker&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>docker version
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;aside class="tip warning">
 This is not recommended on internet facing servers, keep &lt;code>docker&lt;/code> privileges to the &lt;code>root&lt;/code> user.
&lt;/aside></description></item><item><title>Run laptop with the lid closed</title><link>https://humberto.io/bits/run-laptop-with-the-lid-closed/</link><pubDate>Sat, 30 Jul 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/run-laptop-with-the-lid-closed/</guid><description>&lt;p>Edit the &lt;code>/etc/systemd/logind.conf&lt;/code> file, and change the following lines:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#89b4fa">HandleLidSwitch&lt;/span>&lt;span style="color:#89dceb;font-weight:bold">=&lt;/span>&lt;span style="color:#a6e3a1">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#89b4fa">HandleLidSwitchExternalPower&lt;/span>&lt;span style="color:#89dceb;font-weight:bold">=&lt;/span>&lt;span style="color:#a6e3a1">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#89b4fa">HandleLidSwitchDocked&lt;/span>&lt;span style="color:#89dceb;font-weight:bold">=&lt;/span>&lt;span style="color:#a6e3a1">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then restart the service:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>sudo systemctl restart systemd-logind.service
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Turn off laptop screen automatically</title><link>https://humberto.io/bits/turn-off-laptop-screen-automatically/</link><pubDate>Fri, 29 Jul 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/turn-off-laptop-screen-automatically/</guid><description>&lt;p>Edit the &lt;code>/etc/default/grub&lt;/code> file adding the following to the &lt;code>GRUB_CMDLINE_LINUX&lt;/code> variable:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#89b4fa">GRUB_CMDLINE_LINUX&lt;/span>&lt;span style="color:#89dceb;font-weight:bold">=&lt;/span>&lt;span style="color:#a6e3a1">&amp;#34;consoleblank=300&amp;#34; # turn off the screen after 5 minutes&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then update grub:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>sudo update-grub
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Pull from multiple repositories</title><link>https://humberto.io/bits/pull-from-multiple-repositories/</link><pubDate>Mon, 23 May 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/pull-from-multiple-repositories/</guid><description>&lt;p>A tip for when you have a list of git repositories to update:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c &amp;#34;cd &amp;#39;{}&amp;#39; &amp;amp;&amp;amp; git pull &amp;amp;&amp;amp; cd ..&amp;#34; \;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;code>\( ! -name . \)&lt;/code> pattern is used to skip executing the command inside the &lt;code>.&lt;/code> folder.&lt;/p></description></item><item><title>Match and replace line breaks in vim</title><link>https://humberto.io/bits/match-and-replace-line-breaks-in-vim/</link><pubDate>Sun, 20 Feb 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/match-and-replace-line-breaks-in-vim/</guid><description>&lt;p>There are 2 different special characters when dealing with line breaks:&lt;/p>
&lt;ul>
&lt;li>&lt;code>\n&lt;/code> represents the new line character byte &lt;code>0x0a&lt;/code>&lt;/li>
&lt;li>&lt;code>\r&lt;/code> represents the carriage return byte &lt;code>0x0d&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>But in vim at the replacement side of the pattern things change a bit:&lt;/p>
&lt;ul>
&lt;li>&lt;code>\n&lt;/code> becomes the null character &lt;code>0x00&lt;/code>&lt;/li>
&lt;li>&lt;code>\r&lt;/code> becomes the new line character &lt;code>0x0a&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>So at the search side you should use &lt;code>\n&lt;/code> while at replace &lt;code>\r&lt;/code>.&lt;/p>
&lt;p>Example:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>%s/\n/\r/g
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Empty commit</title><link>https://humberto.io/bits/empty-commit/</link><pubDate>Fri, 18 Feb 2022 00:00:00 +0000</pubDate><guid>https://humberto.io/bits/empty-commit/</guid><description>&lt;p>Sometimes you just need to make an empty commit to trigger a CI pipeline or a webhook.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-console" data-lang="console">&lt;span style="display:flex;">&lt;span>git commit --allow-empty -m &amp;#34;Trigger CI&amp;#34;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item></channel></rss>