<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Down the Rabbit Hole - Posts</title>
    <description>Stephen Warren's Blog</description>
    <link>http://rabbithole.wwwdotorg.org/</link>
    
      
        <item>
          <title>Remote Assistance via SSH Reverse Port Forwarding</title>
          <description>&lt;p&gt;My mother lives on a different continent. I sometimes need to provide remote
assistance for her Linux PC, on issues such as printing failures. I wanted to
set up a secure remote access solution that didn’t require any action on my
mother’s part aside from turning on her PC. To make this work, I’ve set up a
port-forwarding outbound SSH connection from her PC to my server.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;background&quot;&gt;Background&lt;/h1&gt;

&lt;p&gt;I wanted to be able to connect to my mother’s PC using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt;, since with that
baseline, I could make anything else work. However, I didn’t want to just open a
port-forward on her firewall/router. A port forward exposes her PC to attack,
and is brittle; if the router is ever replaced, neither the port forward
configuration, nor the static DHCP reservation for her PC that allows it to
work, are likely to be replicated. Remotely walking someone through configuring
this would probably be painful. The alternative was to have her PC make an
outbound connection to a known location, with a remote port forward. Then I can
simply connect to the same location and make use of that remote port forward to
get access to the SSH server on her PC.&lt;/p&gt;

&lt;h1 id=&quot;explanation&quot;&gt;Explanation&lt;/h1&gt;

&lt;p&gt;When my mother’s PC boots, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systemd&lt;/code&gt; unit launches &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; to connect to my
Linode server. This uses a dedicated SSH key that only allows port forwarding;
no command may be run. This connects to a dedicated user ID on the server so if
there is any security issue, only the dedicated account is compromised.&lt;/p&gt;

&lt;p&gt;This SSH connection has some remote port forwards enabled. On the server, it
will listen for connections on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1:1862&lt;/code&gt;, and forward any such connection
back to port 862 on my mother’s PC, where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshd&lt;/code&gt; is running. This listening
socket is only available to processes running on the server, and not exposed
to the general Internet, so is hidden from direct attack. Note that I use
port 862 rather than 22 for SSH on most of my systems to reduce the amount of
port-scanning etc. that SSH has to deal with.&lt;/p&gt;

&lt;p&gt;Whenever I want to connect to my mother’s PC, I use my Linode server as an SSH
jump host. If I was to do this manually, I would:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;On my laptop, connect to my Linode server using SSH, with local port 1862
forwarded to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1:1862&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;On my laptop again, in parallel, connect to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1:1862&lt;/code&gt; using SSH, which
gets forwarded over two SSH connections; first from my laptop to my Linode, and
then over the remote port forward set up by the SSH connection from my
mother’s PC to the Linode, and thus ultimately arrives at the sshd running on my
mother’s PC, where the regular login process proceeds.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using SSH’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ProxyJump&lt;/code&gt; feature in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.ssh/config&lt;/code&gt;, I can automate all of
this; see the configuration files below.&lt;/p&gt;

&lt;p&gt;I also port-forward a variety of ports on my laptop, so that I can connect to
various network services on my mother’s PC and printer.&lt;/p&gt;

&lt;h1 id=&quot;diagram&quot;&gt;Diagram&lt;/h1&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Initial state:
┌────────────┐    ┌───────────────────────┐    ┌───────────┐
│ Mother PC  │    │ Linode server         │    │ My laptop │
│            │    │                       │    │           │
│            │    │           sshd        │    │           │
│            │    │                       │    │           │
│            │    │                       │    │           │
│            │    │                       │    │           │
│            │    │                       │    │           │
│            │    └───────────────────────┘    └───────────┘
│ sshd       │                                               
└────────────┘                                               

Mother PC boots, ssh&apos;d to Linode server, sets up reverse forward:
┌────────────┐    ┌───────────────────────┐    ┌───────────┐
│ Mother PC  │    │ Linode server         │    │ My laptop │
│            │    │                       │    │           │
│            │    │           sshd        │    │           │
│ ssh ───────┼────┼─────► sshd            │    │           │
│            │    │        │              │    │           │
│            │    │   fwd listen          │    │           │
│            │    │                       │    │           │
│ sshd       │    └───────────────────────┘    └───────────┘
└────────────┘                                               

I connect from my laptop, initially to the Linode server as a jump host:
┌────────────┐    ┌───────────────────────┐    ┌───────────┐
│ Mother PC  │    │ Linode server         │    │ My laptop │
│            │    │                       │    │           │
│            │    │           sshd        │    │           │
│ ssh ───────┼────┼─────► sshd    sshd ◄──┼────┼─ssh       │
│  │         │    │        │              │    │           │
│ fwd - - - -│- - ┼ - fwd listen          │    │           │
│            │    │                       │    │           │
│            │    │                       │    │           │
│ sshd       │    └───────────────────────┘    └───────────┘
└────────────┘                                               

The final connection to Mother PC is made via the port forward:
┌────────────┐    ┌───────────────────────┐    ┌───────────┐
│ Mother PC  │    │ Linode server         │    │ My laptop │
│            │    │                       │    │           │
│            │    │           sshd        │    │           │
│ ssh ───────┼────┼─────► sshd    sshd ◄──┼────┼─ssh       │
│  │         │    │        │        │     │    │           │
│ fwd ◄──────┼────┼── fwd listen ◄──┘     │    │           │
│  │         │    │                       │    │           │
│  ▼         │    │                       │    │           │
│ sshd       │    └───────────────────────┘    └───────────┘
└────────────┘                                               &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;(This core of this diagram was created using &lt;a href=&quot;https://asciiflow.com/#/&quot;&gt;asciiflow&lt;/a&gt;.)&lt;/p&gt;

&lt;h1 id=&quot;config-files&quot;&gt;Config Files&lt;/h1&gt;

&lt;h2 id=&quot;mothers-pc&quot;&gt;Mother’s PC&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/systemd/system/wdo-avon-port-forward.service&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[Unit]
Description=avon.wwwdotorg.org port forward
After=network.target

[Service]
User=port_user
ExecStart=/usr/bin/ssh -i /home/port_user/.ssh/id_ed25519_fwds \
    -o ServerAliveInterval=60 \
    -o ExitOnForwardFailure=yes \
    -p 862 -nNT \
    -R 127.0.0.1:1862:127.0.0.1:862 \
    port_user@avon.wwwdotorg.org no_command
RestartSec=15
Restart=always
KillMode=mixed

[Install]
WantedBy=multi-user.target&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;To install and enable that service, run:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;wdo-avon-port-forward.service
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl start wdo-avon-port-forward.service&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;linode-server&quot;&gt;Linode Server&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~port_user/.ssh/authorized_keys&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;# Also allow -L for (unused) port 100 since permitopen=none disallows connection/port-forwarding
restrict,command=&quot;bash -c &apos;while true; do sleep 60; done&apos;&quot;,port-forwarding,permitopen=&quot;127.0.0.1:100&quot; ssh-ed25519 CLIENT_PUBKEY_ELIDED&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;my-laptop&quot;&gt;My Laptop&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~swarren/.ssh/config&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Host woodland-4x
    User elided
    IdentityFile /home/swarren/.ssh/id_ed25519_xxx
    HostName 127.0.0.1
    Port 1862
    ProxyJump swarren@avon.wwwdotorg.org:862
    LocalForward 8631 127.0.0.1:631 # CUPS
    LocalForward 5800 127.0.0.1:5800 # VNC web
    LocalForward 5900 127.0.0.1:5900 # VNC
    LocalForward 8080 192.168.1.14:80 # HP printer HTTP
    LocalForward 8443 192.168.1.14:443 # HP printer HTTPS&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Of course, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~elided/.ssh/authorized_keys&lt;/code&gt; on my mother’s PC contains entries for
swarren’s SSH keys on my laptop, as does &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~swarren/.ssh/authorized_keys&lt;/code&gt; on the
Linode server.&lt;/p&gt;

&lt;p&gt;How I connect:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;ssh woodland-4x&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Example URL I open in the web browser: &lt;a href=&quot;https://127.0.0.1:8443/&quot;&gt;https://127.0.0.1:8443/&lt;/a&gt; (for access to
the printer’s admin web page).&lt;/p&gt;

&lt;h1 id=&quot;vnc&quot;&gt;VNC&lt;/h1&gt;

&lt;p&gt;Once I’ve connected, I can run the following on my mother’s PC to run a
screen-scraping VNC server:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;x11vnc &lt;span class=&quot;nt&quot;&gt;-rfbauth&lt;/span&gt; ~/.vnc/passwd &lt;span class=&quot;nt&quot;&gt;-localhost&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-display&lt;/span&gt; :0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Don’t forget to perform one-time setup to set the password using:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;x11vnc &lt;span class=&quot;nt&quot;&gt;-storepasswd&lt;/span&gt; ~/.vnc/passwd&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;… and connect to it from my laptop by running:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;gvncviewer localhost:0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;changelog&quot;&gt;Changelog&lt;/h1&gt;

&lt;p&gt;2026/10/21:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Fixed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; cmdline args (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-R&lt;/code&gt; vs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-L&lt;/code&gt;) in the systemd unit file to match
what’s really there. This file wasn’t available when I wrote the blog post,
so I used a similar-but-different system for reference.&lt;/li&gt;
  &lt;li&gt;Reformatted systemd unit file so it’s more readable. Unfortunately, the
syntax likely cannot be pasted directly now due to the manual line-breaks.&lt;/li&gt;
  &lt;li&gt;Added note about use of alternate SSH port number.&lt;/li&gt;
  &lt;li&gt;Enhanced some text. Moved diagram after explanation for better context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2026/10/22:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Expanded the diagram to individual steps.&lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2026-10-20T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2026/10/20/ssh-port-fwd-remote-assistance.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2026/10/20/ssh-port-fwd-remote-assistance.html</guid>
        </item>
      
    
      
        <item>
          <title>Disabling the Touchpad During Login</title>
          <description>&lt;p&gt;I was having recurring trouble logging into my laptop. Eventually I realized
that I was accidentally touching my mousepad while typing my password, which
caused subsequent typing to go to the middle of my password instead of the
end. Naturally the system didn’t accept this variant of my password! Here’s
how I avoided this issue.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;automatic-touchpad-disabling-when-logged-in&quot;&gt;Automatic Touchpad Disabling When Logged In&lt;/h1&gt;

&lt;p&gt;When I’m logged in, I configured XFCE to disable my touchpad while typing,
which solves the same issue. Do this via XFCE settings &amp;gt; Mouse and Touchpad &amp;gt;
Device tab &amp;gt; Device: SynPS/2 Synaptics TouchPad &amp;gt; Touchpad tab &amp;gt; check “Disable
touchpad whlie typing”.&lt;/p&gt;

&lt;p&gt;However, I couldn’t work out if there was a way to apply the same setting at
the login screen too. In the end, I decided to completely disable the touchpad
at the login screen, then re-enable it upon successful login. I can still use
the trackpoint (red button) mouse if I need to use a mouse while logging in.&lt;/p&gt;

&lt;h1 id=&quot;a-failed-attempt-using-xinput&quot;&gt;A Failed Attempt Using xinput&lt;/h1&gt;

&lt;p&gt;Theoretically, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xinput&lt;/code&gt; command may be used to disable/reenable the
touchpad:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;xinput list
...
⎜   ↳ SynPS/2 Synaptics TouchPad              	&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;10	&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;slave  pointer  &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;2&lt;span class=&quot;o&quot;&gt;)]&lt;/span&gt;
...
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;xinput &lt;span class=&quot;nt&quot;&gt;--disable&lt;/span&gt; 10
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;xinput &lt;span class=&quot;nt&quot;&gt;--ensable&lt;/span&gt; 10&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Unfortunately, if you have the Synaptics driver installed (Debian package
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xserver-xorg-input-synaptics&lt;/code&gt;), then the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--disable&lt;/code&gt; command works, but
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable&lt;/code&gt; doesn’t! This is a bit of a problem…&lt;/p&gt;

&lt;h1 id=&quot;disabling-the-touchpad-using-synclient&quot;&gt;Disabling The Touchpad Using synclient&lt;/h1&gt;

&lt;p&gt;It turns out the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;synclient&lt;/code&gt; command can also control a Synaptics touchpad,
and specifically can disable/re-enable it. This approach works!&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;synclient &lt;span class=&quot;nv&quot;&gt;touchpadoff&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;synclient &lt;span class=&quot;nv&quot;&gt;touchpadoff&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;automating-lightdm&quot;&gt;Automating Lightdm&lt;/h1&gt;

&lt;p&gt;To run these commands at the login prompt (to disable the touchpad), and when
the user has logged in (to re-enable it), simply add the following to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/lightdm/lightdm.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[Seat:*]
greeter-setup-script=synclient touchpadoff=1
session-setup-script=synclient touchpadoff=0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Note that if you’re using a different display manager, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdm&lt;/code&gt;, you’ll
need to automate this in a different way.&lt;/p&gt;
</description>
          <pubDate>2026-07-28T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2026/07/28/disabling-touchpad-during-login.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2026/07/28/disabling-touchpad-during-login.html</guid>
        </item>
      
    
      
        <item>
          <title>Fixing Outlook reminders with AutoHotkey</title>
          <description>&lt;p&gt;When I was forced to change from Classic Outlook to New Outlook, I lost the
ability to control the location of the notification window, which in turn
made it hard to notice, and caused me to be late for some meetings. Here’s
the story of how I fixed this.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-problem&quot;&gt;The Problem&lt;/h1&gt;

&lt;p&gt;Classic Outlook would create a notification window by default. With new Outlook,
I had to change the notification settings to get the same behavior; at least
this was an option!&lt;/p&gt;

&lt;p&gt;However, the notification window didn’t behave the same. With Classic Outlook,
the notification window could be moved to the desired location, and would
re-open in that same location when it was shown again. New Outlook doesn’t
remember the position. Despite the settings stating that it would always
appear in the center of the screen, it actually appears near the top-left of
the screen. I run Outlook within a virtual machine, and typically some local
window covers the top-left of the VM viewer window, so the notification
window isn’t visible:-(&lt;/p&gt;

&lt;h1 id=&quot;first-attempt-at-a-solution&quot;&gt;First Attempt at a Solution&lt;/h1&gt;

&lt;p&gt;To solve this, I needed some way to override the location of the notification
window outside of Outlook. After some investigation, I found
&lt;a href=&quot;https://www.autohotkey.com/&quot;&gt;AutoHotkey&lt;/a&gt;, an automation tool for Windows.
This tool has the ability to write scripts that perform many actions, such as
searching for, moving, or setting the “always on top” attribute for a window.&lt;/p&gt;

&lt;p&gt;Initially, I wrote the AutoHotkey script roughly as follows:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;#Requires AutoHotkey v2.0

SetTitleMatchMode(&quot;RegEx&quot;)
TargetTitle := &quot;Reminders - .* - Outlook&quot;

loop {
    hwnd := WinWait(TargetTitle)
    WinMove(1270, 1270, , , hwnd)
    WinSetAlwaysOnTop(1, hwnd)
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;However, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WinWait()&lt;/code&gt; only waits for a searched-for window to exist; it doesn’t
wait for a &lt;em&gt;new&lt;/em&gt; window to be created. Thus, this solution works the first
time, but then continually finds the same window over and over, triggering
high CPU usage. What I needed was a way to detect when a new window was
created, or otherwise react to that event.&lt;/p&gt;

&lt;p&gt;After more research I found the
&lt;a href=&quot;https://github.com/Descolada/AHK-v2-libraries/blob/main/Lib/WinEvent.ahk&quot;&gt;WinEvent&lt;/a&gt;
library for AutoHotkey. This library will call a user-provided function
whenever a specific event occurs.&lt;/p&gt;

&lt;h1 id=&quot;the-final-solution&quot;&gt;The Final Solution&lt;/h1&gt;

&lt;p&gt;The final script is shown below. It installs a callback/event-handler for the
“window shown” event. This function is called one time whenever a window is
shown for the first time, thus avoiding the infinite loop mentioned above.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;#Requires AutoHotkey v2.0

#include &quot;WinEvent.ahk&quot;

SetTitleMatchMode(&quot;RegEx&quot;)
TargetTitle := &quot;Reminders - .* - Outlook&quot;
WinEvent.Show(OnOutlookReminderCreated, TargetTitle)

OnOutlookReminderCreated(hWnd, hook, dwmsEventTime) {
    WinMove(1270, 1270, , , hwnd)
    WinSetAlwaysOnTop(1, hwnd)
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Save this as e.g. `Move Outlook Reminder Window.ahk’. Once the file is saved,
it can be run directly (e.g. double-click it in Windows File Explorer) for
testing purposes.&lt;/p&gt;

&lt;h1 id=&quot;automatic-startup&quot;&gt;Automatic Startup&lt;/h1&gt;

&lt;p&gt;The final part of the solution was to cause the AutoHotkey script to run
automatically each time the machine was rebooted, or I logged in. This is a
simple matter of placing the script into the Windows startup folder, or at
least placing a shortcut/link to the script into the startup folder. Here are
some instructions to do that, cribbed from either Stack Overflow or the
AutoHotkey forums.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Locate your script: Find your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ahk&lt;/code&gt; file in File Explorer.&lt;/li&gt;
  &lt;li&gt;Create a shortcut: Right-click the script and select Create shortcut.&lt;/li&gt;
  &lt;li&gt;Open the Startup folder: Press Win + R, type explorer, and hit Enter. In the URL/location bar, enter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shell:startup&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Move the shortcut: Drag or paste the newly created shortcut into this folder.&lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2026-04-23T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2026/04/23/fixing-outlook-reminders-with-autohotkey.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2026/04/23/fixing-outlook-reminders-with-autohotkey.html</guid>
        </item>
      
    
      
        <item>
          <title>File sharing for AWS cloud VMs/VDIs</title>
          <description>&lt;p&gt;My old work cloud-based VM used VMWare Horizon, which had built-in support for
accessing the client machine’s files from the VM. Recently, I had to switch to
an AWS VM instead, and the Linux client/viewer app doesn’t support file-
sharing, so I had to roll my own solution. Here’s how.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-feature-i-lost&quot;&gt;The Feature I Lost&lt;/h1&gt;

&lt;p&gt;If you use VMWare’s Horizon client application to connect to and view a VMWare
VM/VDI, it will/can automatically create a network drive on the VM which allows
access to the user’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME&lt;/code&gt; directory on the client machine. This makes it
extremely easy to transfer files between the client machine and VM using
regular Windows GUI tools like File Explorer.&lt;/p&gt;

&lt;p&gt;Other techniques like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; certainly exist, and have their place. However,
there’s nothing as simple as “File -&amp;gt; Save As” or “Attach a File” in e.g.
Outlook being able to directly read/write your client machine’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME&lt;/code&gt;
without any other steps.&lt;/p&gt;

&lt;h1 id=&quot;samba-to-the-rescue&quot;&gt;Samba To The Rescue&lt;/h1&gt;

&lt;p&gt;The core technology is &lt;a href=&quot;https://www.samba.org/&quot;&gt;Samba&lt;/a&gt;, a piece of server that
turns a Linux system into a Windows file server. We just need a plus a few
network configuration steps, and a simple Samba configuration file.&lt;/p&gt;

&lt;h1 id=&quot;network-connectivity--client-hostname&quot;&gt;Network Connectivity &amp;amp; Client Hostname&lt;/h1&gt;

&lt;p&gt;There is one critical assumption: That there is an IP network path from the VM
back to the client system. Typically, the client application connects to the VM,
and any file-sharing network traffic is tunneled within this connection. With
the setup described in this post, the Windows machine must contact the client
machine using the standard Windows file sharing protocol (SMB). This requires&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;A network path from the VM back to the client. I.e any intermediate router,
firewall, or VPN doesn’t block this. My company VPN does allow this, at least
for some connectivity paths.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The client must have a consistent (known a-priori) hostname or IP address
that can be used to set up the network drive mapping on the VM.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;client-system-hostname&quot;&gt;Client System Hostname&lt;/h1&gt;

&lt;p&gt;My company runs an internal dynamic DNS system, which allows end-user systems
to register internal names like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;your-pc-name.dynamic.company.com&lt;/code&gt;. These can
be updated automatically whenever a VPN connection is complete. This gives a
well-known name that may be used to contact your client system, whatever IP
address it has, and whether it’s connected to the company LAN or VPN.&lt;/p&gt;

&lt;h1 id=&quot;firewall-configuration&quot;&gt;Firewall Configuration&lt;/h1&gt;

&lt;p&gt;Exposing any Windows file server to arbitrary networks isn’t a good idea,
simply in terms of reducing attack surface. It’s best to configure a firewall
on the client machine that only allows SMB connections from the specific IP
address (or subnet) of the relevant VM(s). If your file server software has a
security vulnerability, this prevents anyone from attacking you!&lt;/p&gt;

&lt;p&gt;Assuming your VM’s IP is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10.1.2.3&lt;/code&gt;, run the following command to allow access
from it:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;sudo ufw allow from 10.1.2.3/32 to any app Samba&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It is assumed that the default state of the firewall is to disallow all forms
of inbound traffic.&lt;/p&gt;

&lt;h1 id=&quot;samba-configuration&quot;&gt;Samba Configuration&lt;/h1&gt;

&lt;p&gt;Samba needs very little active configuration; the default configuration file
(at least on Ubuntu) already contains most of what you need. Here’s the file I
ended up with. I believe I edited the values for fields &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;workgroup&lt;/code&gt; and
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;netbios name&lt;/code&gt;, and uncommented the whole &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;homes&lt;/code&gt; section and perhaps edited
some/all of its field values.&lt;/p&gt;

&lt;p&gt;To install Samba:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;sudo apt update
sudo apt -y install samba&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now create or edit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/samba/smb.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[global]
   workgroup = COMPANY.COM
   netbios name = choose-a-name
   server string = %h server (Samba, Ubuntu)
   log file = /var/log/samba/log.%m
   max log size = 1000
   logging = file
   panic action = /usr/share/samba/panic-action %d
   server role = standalone server
   obey pam restrictions = yes
   unix password sync = yes
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
   pam password change = yes
   map to guest = bad user
   usershare allow guests = no
[homes]
   comment = Home Directories
   browseable = no
   valid users = %S&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Samba requires authentication, at least for shared with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;valid users&lt;/code&gt;
configured. You will need to log in using a username that exists in the Linux
user list (typically your own regular user ID, so that your own home directory
is shared), and a Samba-specific password. To set the password:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;smbpasswd -a your_linux_username&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;… and enter your desired Samba password.&lt;/p&gt;

&lt;p&gt;Now configure which Samba processes should start, and restart them so they use
the latest configuration file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;servicectl disable nmdb
servicectl enable smdb
service smbd restart&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;windows-configuration&quot;&gt;Windows Configuration&lt;/h1&gt;

&lt;p&gt;In Windows File Explorer, you should be able to type
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\\your-pc-name.dynamic.company.com\username&lt;/code&gt; into the URL bar. When prompted
for authentication, user your username, and the password you set above.&lt;/p&gt;

&lt;p&gt;Once this is working, you can map a network drive, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Z:&lt;/code&gt; to that path,
so that it provides a simple path that is available whenever the VM reboots.&lt;/p&gt;
</description>
          <pubDate>2026-03-06T00:00:00-07:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2026/03/06/samba-for-aws-vdi-file-sharing.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2026/03/06/samba-for-aws-vdi-file-sharing.html</guid>
        </item>
      
    
      
        <item>
          <title>Fixing AWS Nice dcvviewer with keyd</title>
          <description>&lt;p&gt;I recently had to switch provider for cloud-based Windows VMs. After firing up
the new VM and its viewer application (AWS Nice &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dcvviewer&lt;/code&gt;), I found that basic
features such as Alt-Tab and mouse forward &amp;amp; backward buttons didn’t work. This
was an annoying productivity drain, so I set out to solve the problem. Here’s
the story of how I fixed it using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; key remapping tool.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;what-do-these-keys-do&quot;&gt;What Do These keys Do?&lt;/h1&gt;

&lt;p&gt;In case you aren’t familiar with these keyboard shortcuts, here’s a brief
description of what they are and why you’d use them. Apparently even some of
our IT employees had never heard of these!&lt;/p&gt;

&lt;dl&gt;
  &lt;dt&gt;Alt-Tab&lt;/dt&gt;
  &lt;dd&gt;Switches between windows or applications. Use this if you have your hands on
the keyboard rather than the mouse; it’s much quicker than moving your hand
back to the mouse and clicking the relevant window in the task bar!&lt;/dd&gt;
  &lt;dt&gt;Mouse buttons&lt;/dt&gt;
  &lt;dd&gt;Most non-cheap modern mice have forward and backward buttons in addition to
the regular left and right buttons. These are useful when using a web browser
or file explorer, to page through your tab history.&lt;/dd&gt;
&lt;/dl&gt;

&lt;h1 id=&quot;early-attempts&quot;&gt;Early Attempts&lt;/h1&gt;

&lt;p&gt;I did a lot of research via Google searches, and found many other people had
reported the same issue. Still, Amazon hasn’t fixed it for some reason.
Ultimately I didn’t find any kind of complete fix, just disappointed users.&lt;/p&gt;

&lt;p&gt;That said, someone did point out that Alt-Windows-Tab did work. I also realized
that there were keyboard shortcuts that work the same as the mouse forward &amp;amp;
backward buttons (Alt-Left, Alt-Right), at least in a browser and file explorer
window. Experiments with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xdotool&lt;/code&gt; showed that the
alternative keystrokes could be injected in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dcvviewer&lt;/code&gt;; a path towards a fix
was appearing!&lt;/p&gt;

&lt;h1 id=&quot;keyd-to-the-rescue&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; to the Rescue&lt;/h1&gt;

&lt;p&gt;What I needed was a keyboard remapping tool; something that would detect when
I’d pressed a specific key, translate it to some other keycode, and send that
to the application instead. I tried a few such tools that didn’t work, but
eventually found &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt;, which did! &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; isn’t packaged for Ubuntu, so I had
to install it from a PPA:&lt;/p&gt;

&lt;h2 id=&quot;installation&quot;&gt;Installation&lt;/h2&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;$ sudo add-apt-repository ppa:keyd-team/ppa
$ sudo apt install keyd keyd-application-mapper&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We only want to send modified keycodes to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dcvviewer&lt;/code&gt; application, so that
local applications are not affected. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd-application-mapper&lt;/code&gt; is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt;
add-on that enables this.&lt;/p&gt;

&lt;h2 id=&quot;selecting-input-devices&quot;&gt;Selecting Input Devices&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; needs to be informed which input devices (keyboards, mice) to handle. To
do so, create configuration file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/keyd/default.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[ids]
# Laptop keyboard
0001:0001
# Targus USB keyboard
0461:0010
# Logitech USB mouse
046d:c069&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The IDs may be found by running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lsusb&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin/keyd.rvaiya monitor&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;configuring-key-remappings&quot;&gt;Configuring Key Remappings&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; supports a few configuration files. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd-application-mapper&lt;/code&gt;
specifically is configured via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.config/keyd/app.conf&lt;/code&gt;; create it with the
following content:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[dcvviewer]
alt.tab = M-A-tab
mouse1 = A-left
mouse2 = A-right&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;starting-keyd&quot;&gt;Starting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Enable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; to run at boot, and start/restart it now that all necessary
configuration files are in place:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;systemctl enable keyd
service keyd restart&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Arrange for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin/keyd-application-mapper -d&lt;/code&gt; to be run when you log in.
For debugging, you may run that command directly in a terminal. For
persistence, you might launch it from your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.xsession&lt;/code&gt; file, or in XFCE, visit
Settings &amp;gt; Session and Startup &amp;gt; Application Autostart, and add a new entry for
this command.&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keyd&lt;/code&gt; running, I can now focus the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dcvviewer&lt;/code&gt; window and use the
keyboard and mouse as normal. I no longer have to remember to use a completely
different set of keyboard shortcuts based on whether I’m using a local
application, or a remote Windows session via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dcvviewer&lt;/code&gt;.&lt;/p&gt;

&lt;h1 id=&quot;caveats&quot;&gt;Caveats&lt;/h1&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin/keyd-application-mapper&lt;/code&gt; can remap keys based on the local
application that has focus. It can’t detect which application has focus within
a remote viewer application such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dcvviewer&lt;/code&gt;. Thus if some Windows
application uses a different keyboard shortcut that Alt-Left for the back mouse
button, I won’t be able to solve that. Still, this is a pretty common keyboard
equivalent, so touch wood this won’t come up!&lt;/p&gt;
</description>
          <pubDate>2026-02-28T00:00:00-07:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2026/02/28/fixing-aws-nice-dcvviewer-with-keyd.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2026/02/28/fixing-aws-nice-dcvviewer-with-keyd.html</guid>
        </item>
      
    
      
        <item>
          <title>GPG agent forwarding via SSH</title>
          <description>&lt;p&gt;Have you ever wanted to combine GPG, GPG agent, and SSH socket forwarding? It’s
something I’ve been looking forward to for a while. The last time I tried it,
many years ago, it just wasn’t ready. But a few days ago I tried it out again
and it all works! Read on for an explanation of what these things are, and why
they’re useful.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;what-are-all-these-things&quot;&gt;What Are All These Things?&lt;/h1&gt;

&lt;h2 id=&quot;gpg&quot;&gt;GPG&lt;/h2&gt;

&lt;p&gt;GPG (&lt;a href=&quot;https://gnupg.org/&quot;&gt;GNU Privacy Guard&lt;/a&gt;) is an application that lets you
encrypt/decrypt files. For example, I might want to keep some API key handy,
but not leave it lying around in plain-text. Instead of simply storing the API
key in a plain-text file, I’ll encrypt the API key using GPG, then save the
encrypted result in a file. Whenever I need to use the API key, I’ll
temporarily decrypt it using GPG, and pass it to whatever program needs the
key, e.g. through a pipe, without ever saving the plain-text API key to disk.&lt;/p&gt;

&lt;h2 id=&quot;gpg-agent&quot;&gt;GPG Agent&lt;/h2&gt;

&lt;p&gt;GPG uses keys to encrypt/decrypt data, and these need to be available while
running GPG. If we simply stored the GPG keys on disk in plain-text, anyone who
gained access to the filesystem could easily use the GPG keys to decrypt any
data that GPG had created. Luckily, GPG supports encrypting keys with a
pass-phrase, and storing the keys in an encrypted form, which prevents trivial
theft of the keys.&lt;/p&gt;

&lt;p&gt;(Side-note: Use full disk encryption too. GPG key pass-phrases also mitigates
attacks by malicious code that somehow executes as your own user ID.)&lt;/p&gt;

&lt;p&gt;However, this makes repetitive use of GPG a bit annoying; you have to type in
your (preferably long and secure) GPG key pass-phrase every time you use it. To
aid ease-of-use, you can run a program called a GPG agent. The GPG agent
manages loading and decrypting of keys. Once a key is used, the GPG agent
caches it in (locked, non-swappable) memory for a short time. If the key is
used again while it’s cached, there’s no need to re-enter the pass-phrase.&lt;/p&gt;

&lt;p&gt;How does this work? The GPG agent is a long-running background program. It
listens on a Unix domain socket for connections from the user-run GPG
application. Each time GPG runs, it connects to this domain socket to acquire
keys.&lt;/p&gt;

&lt;p&gt;How is this secure? The Unix domain socket can only be accessed by processes
running on the same machine as the GPG agent. Unix domain sockets can only be
accessed via the filesystem or other local means. File system permissions
protect the domain socket against access by most other local users, with the
exception at least of root.&lt;/p&gt;

&lt;h2 id=&quot;ssh&quot;&gt;SSH&lt;/h2&gt;

&lt;p&gt;SSH (&lt;a href=&quot;https://www.openssh.com/&quot;&gt;Secure Shell&lt;/a&gt;) is a utility that enables secure
command-line access to remote machines. The most basic usage is to run the
SSH client application on your local system, and connect to a remote system,
yielding the ability to execute shell commands remotely. However, SSH has
many other features.&lt;/p&gt;

&lt;p&gt;One of these features is the ability to forward sockets/ports between the local
and remote system. This can be used in many ways, such as to allow a network
client application running on the remote system to connect to a network server
application running on (or accessible from) the local system, whilst tunnelling
all the traffic inside the secure and encrypted SSH session.&lt;/p&gt;

&lt;p&gt;Historically, SSH only supported forwarding TCP sockets, but in more recent
versions, support was added for forwarding Unix domain sockets too.&lt;/p&gt;

&lt;h1 id=&quot;combining-them-together-and-why&quot;&gt;Combining Them Together, and Why?&lt;/h1&gt;

&lt;p&gt;So: GPG agent listens on a Unix domain socket. SSH now supports forwarding Unix
domain sockets. Can we combine the two so that we can SSH to a remote system,
run GPG there, and have it connect to a local GPG agent? Yes, we can!&lt;/p&gt;

&lt;p&gt;What’s the use-case? I’m working from home, as many people are these days. I
need to run a script on my desktop in the office. The script needs to make
requests to a web-service, and needs an API token to do so. As mentioned
before, the API token is stored in a GPG-encrypted file on my office desktop.
Without GPG agent forwarding, every time I run the script, I need to type my
GPG key pass-phrase into the SSH session, which is repetitive and error-prone. I
could run a GPG agent on the desktop, but then I’d have to manage starting
and stopping the GPG agent on the desktop, and still have to unlock the key
every time I connected and started the agent. I would need to repeat this
process for each remote machine that I access. If I could forward the GPG agent
connection from my work desktop to my laptop, I could manage unlocking GPG
keys in one place; on the laptop.&lt;/p&gt;

&lt;h1 id=&quot;a-security-warning&quot;&gt;A Security Warning&lt;/h1&gt;

&lt;p&gt;There are some disadvantages (but also advantages) to SSH and GPG agent
forwarding. Please familiarize yourself with them before deciding to use these
features.&lt;/p&gt;

&lt;h2 id=&quot;disadvantages&quot;&gt;Disadvantages&lt;/h2&gt;

&lt;p&gt;Any process on the remote machine that can access the forwarded socket can make
use of your keys. If the agents protocol used a TCP network socket, this would
be a &lt;em&gt;critical&lt;/em&gt; flaw, since TCP sockets are quite widely accessible in general
by default; even restricting access to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;localhost&lt;/code&gt; is nowhere near enough to be
secure. However, the agent protocols run over Unix domain sockets, which allow
for access control. However, Unix domain sockets are still subject to undesired
access, e.g. by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;, or if socket file permissions are accidentally set
permissively. In general, you should consider that any user of a machine to
which you connect with agent forwarding enabled may be able to make use of your
keys. This also applies to any unexpected/unknown or malicious software that’s
running under your uid.&lt;/p&gt;

&lt;p&gt;In my use-case, I’m connecting to machines where I’m the only user, so I have
accepted the risk. This condition may not apply in your case!&lt;/p&gt;

&lt;h2 id=&quot;advantages-too&quot;&gt;Advantages Too!&lt;/h2&gt;

&lt;p&gt;Without agent forwarding, I would need to copy my (pass-phrase-protected) SSH
and GPG private keys to any remote system where I needed to use them. This
increases the attack surface; the more copies there are, the higher the
possibility of the keys being compromised. However, when using agent
forwarding, the private (and security-critical) portions of the keys don’t need
to be present on machines where the keys are used; the agent performs all the
key-related operations locally. This increases security since fewer copies of
private keys are required.&lt;/p&gt;

&lt;p&gt;Note: Since I only recently set up GPG agent forwarding, I haven’t actually
experimented with removing my GPG private keys from the remote machines where
I’m making use of agent forwarding. I hope to try this out soon.&lt;/p&gt;

&lt;p&gt;Another nice feature of some SSH (and GPG?) agents is that they can alert you
when an already-unlocked key is used. The alert will be accompanied by a yes/no
prompt so that you can deny access. This is much easier than re-entering a
pass-phrase, but still allows for confirmation of key use. This worked well for
me when I was running an older version of Ubuntu on my laptop, which contained
a different SSH agent. Unfortunately the latest desktop-oriented SSH agents
don’t seem to implement this feature:-( I’m not sure whether any GPG agent(s)
implement it either. This would be a nice feature for somebody to resurrect.&lt;/p&gt;

&lt;p&gt;Finally, at least with SSH agent forwarding, when you disconnect from a
machine, you may be certain that access-to/use-of keys is not possible by that
machine, since the keys themselves are only ever accessible on the client.
Note: With SSH agent forwarding, I believe that private key operations are
performed by the agent, and results returned to the client, rather than the
private key itself. I imagine that the GPG agent protocol works in a similar
way. However, I am not sure on this point.&lt;/p&gt;

&lt;h1 id=&quot;version-notes&quot;&gt;Version Notes&lt;/h1&gt;

&lt;p&gt;The rest of this post is written based on forwarding a GPG agent running on an
Ubuntu 20.04 system to other systems. My system runs the XFCE desktop
environment, which may influence the selection or operation of the GPG agent.
You may find differences in behavior and paths if you’re running a different
Linux distribution, different SSH or GPG versions, or a different desktop
environment.&lt;/p&gt;

&lt;h1 id=&quot;server-setup&quot;&gt;Server Setup&lt;/h1&gt;

&lt;p&gt;You will almost certainly want to enable the following option in
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/ssh/sshd_config&lt;/code&gt; on each remote system:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;StreamLocalBindUnlink yes&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Whenever a Unix domain socket is forwarded, SSH needs to create the socket in
some filesystem path on the remote system. If the path already exists, this
will fail. This option tells the SSH server to delete the path before creating
the socket, to maximize the chance of success.&lt;/p&gt;

&lt;p&gt;You will need to restart the SSH daemon after making this change.&lt;/p&gt;

&lt;h1 id=&quot;gpg-agent-paths&quot;&gt;GPG Agent Paths&lt;/h1&gt;

&lt;p&gt;How do we know which Unix domain socket to forward? Older versions of GPG
stored the socket path in environment variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GPG_AGENT_INFO&lt;/code&gt;. However, this
variable is now obsolete. Instead, GPG seems to rely on some well-known
pathname these days. This may be related to whether various desktop/systemd
integration features are enabled. The simplest way to find the path is to
simply run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gpg&lt;/code&gt; under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strace&lt;/code&gt; on each system (local and remote), and see
which socket path it connects to. Then, we can set up a forwarding between
these two paths.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;strace -e connect gpg -d /path/to/file.gpg
connect(6, {sa_family=AF_UNIX, sun_path=&quot;/run/user/1000/gnupg/S.gpg-agent&quot;}, 34) = 0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In my case, I find the following paths:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/run/user/1000/gnupg/S.gpg-agent&lt;/code&gt; on my Ubuntu 20.04 laptop, where I am
logged in as uid 1000; a typical value for the first user added to an Ubuntu
system.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/run/user/4321/gnupg/S.gpg-agent&lt;/code&gt; on a system I connect to where I’ve chosen
my uid to match an externally-managed user database.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home/swarren/.gnupg/S.gpg-agent&lt;/code&gt; on an older system that I connect to, and
where for whatever reason GPG doesn’t connect to an agent socket in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/run&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;sgpg-agentextra&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S.gpg-agent.extra&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;(At least the version I’m running of) GPG agent actually listens on a number of
paths. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S.gpg-agent&lt;/code&gt; is intended for local use. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S.gpg-agent.extra&lt;/code&gt; is
apparently a more restricted channel, and more suitable for use with agent
forwarding. You probably want to forward this path.&lt;/p&gt;

&lt;h1 id=&quot;manual-forwarding&quot;&gt;Manual Forwarding&lt;/h1&gt;

&lt;p&gt;Before trying agent forwarding, you probably want to ensure that you can simply
SSH to the relevant remote host and run GPG there without issue. You’ll need
your keys on the remote host and to either manually enter your GPG key
pass-phrase or have a agent running on the remote machine. Once this is
working, you will have debugged any issues solely related to GPG itself,
separately from the added complication of using GPG agent forwarding.&lt;/p&gt;

&lt;p&gt;SSH port forwarding is available from the command-line:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;ssh &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; /home/swarren/.gnupg/S.gpg-agent:/run/user/1000/gnupg/S.gpg-agent.extra somehost
gpg &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; /path/to/file.gpg
&lt;span class=&quot;c&quot;&gt;# Now, your local agent should provide the key,&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# or prompt you for the key pass-phrase.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That’s a bit of a mouthful to type. Luckily, we can automate it!&lt;/p&gt;

&lt;h1 id=&quot;automated-forwarding&quot;&gt;Automated Forwarding&lt;/h1&gt;

&lt;p&gt;We can add entries to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.ssh/config&lt;/code&gt; to request SSH to enable forwarding
without having to specify options on the command-line each time. For example:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Host somehost
    RemoteForward /home/swarren/.gnupg/S.gpg-agent /run/user/1000/gnupg/S.gpg-agent.extra &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;conditional-forwarding&quot;&gt;Conditional Forwarding&lt;/h1&gt;

&lt;p&gt;You may need to use different socket paths for different pairs of machines:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Host somehost
    RemoteForward /home/swarren/.gnupg/S.gpg-agent /run/user/1000/gnupg/S.gpg-agent.extra 
Host otherhost
    RemoteForward /run/user/4321/gnupg/S.gpg-agent /run/user/1000/gnupg/S.gpg-agent.extra &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You may need to vary your configuration based on which system you’re running
SSH &lt;em&gt;from&lt;/em&gt;. For example, so as to only forward from some machines, or to
forward a different agent path from each machine. You can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh_config&lt;/code&gt;’s
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Match&lt;/code&gt; rules to do this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Match host somehost exec &quot;[ $(hostname) == laptop ]&quot;
    RemoteForward /home/swarren/.gnupg/S.gpg-agent /run/user/1000/gnupg/S.gpg-agent.extra 
Match host somehost exec &quot;[ $(hostname) == desktop ]&quot;
    RemoteForward /home/swarren/.gnupg/S.gpg-agent /run/user/9876/gnupg/S.gpg-agent.extra &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Finally, you might not want to enable agent forwarding all the time. Perhaps
you want to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh somehost&lt;/code&gt; normally, but be able to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh somehost-agent&lt;/code&gt; when
you need agent forwarding. That would limit the amount of time your agent
socket is forwarded and exposed to code running on the remote system. You can
combine the previous techniques, plus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh_config&lt;/code&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hostname&lt;/code&gt; statement to
create a virtual destination hostname that works this way:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Match host somehost-agent exec &quot;[ $(hostname) == laptop ]&quot;
    Hostname somehost.domain
    HostKeyAlias somehost.domain
    RemoteForward /home/swarren/.gnupg/S.gpg-agent /run/user/1000/gnupg/S.gpg-agent.extra &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;(I haven’t actually tried out that last option yet, but it’s a combination of
configuration options that I have already used separately.)&lt;/p&gt;

&lt;h1 id=&quot;gotchas-and-negative-interactions&quot;&gt;Gotchas and Negative Interactions&lt;/h1&gt;

&lt;p&gt;If you mix local interactive and SSH logins to a system, you may find that GPG
agent forwarding breaks use of the GPG agent from local sessions. That’s
because GPG agent forwarding deletes and replaces any agent socket that might
have been provided by a local GPG agent. When switching back to a local
interactive login, you may need to restart the daemon. If you log out and log
in, rather that simply locking your screen, this probably happens
automatically. Otherwise, you might need to run a command such as:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;systemctl &lt;span class=&quot;nt&quot;&gt;--user&lt;/span&gt; restart gpg-agent&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;When using GPG agent forwarding, it’s possible you need to stop any GPG agent
running on the remote system:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;systemctl &lt;span class=&quot;nt&quot;&gt;--user&lt;/span&gt; stop gpg-agent&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;… then log out of SSH and reconnect. While experimenting, I believe stopping
the GPG agent on the remote machine helped bypass some issues, but I may simply
be imagining this, and have conflated the issue with having accidentally
specified the wrong agent paths to forward.&lt;/p&gt;
</description>
          <pubDate>2021-03-03T00:00:00-07:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2021/03/03/gpg-agent-fwding-over-ssh.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2021/03/03/gpg-agent-fwding-over-ssh.html</guid>
        </item>
      
    
      
        <item>
          <title>Docker: Avoiding temporary ADD and COPY layers</title>
          <description>&lt;p&gt;Recently, I’ve been working on creating Docker containers. Minimizing the image
size is a topic of interest. A common pattern seems to be to ADD or COPY some
data into the container, use it, and then delete it. This bloats the image.
However, there’s a way to solve this!&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-problem&quot;&gt;The Problem&lt;/h1&gt;

&lt;p&gt;In my case, I needed to install various Debian packages into the image.
However, these packages were not acquired using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt&lt;/code&gt;, but instead through
Docker image context or HTTP download. In other words, like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;FROM ubuntu:20.04
# From context supplied by host
COPY /foo.deb /
RUN dpkg -i /foo.deb &amp;amp;&amp;amp; rm /foo.deb&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;or:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;FROM ubuntu:20.04
ADD https://server.com/foo.deb /
RUN dpkg -i /foo.deb &amp;amp;&amp;amp; rm /foo.deb&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COPY&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ADD&lt;/code&gt; statement creates a layer in the final Docker image. This
layer contains the file no matte what; the later &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUN&lt;/code&gt; statement simply hides
it from the final view of the filesystem, but can’t actually remove the data
from the earlier layer. This bloats the image.&lt;/p&gt;

&lt;h1 id=&quot;the-solution&quot;&gt;The Solution&lt;/h1&gt;

&lt;p&gt;Docker buildkit added a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--mount&lt;/code&gt; option to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUN&lt;/code&gt; statement. This allows
direct access to data of another image in a multi-stage build, and more. This
allows us to download or otherwise acquire data in one image, and then access
it while building another layer without actually adding it to that target
layer’s filesystem. That’s quite a wordy explanation; perhaps an example will
help:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;FROM ubuntu:20.04 AS downloader
ADD https://server.com/foo.deb /downloads

FROM ubuntu:20.04
RUN --mount=type=bind,from=downloader,source=/downloads,target=/downloads dpkg -i /downloads/*.deb&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Here’s an explanation:&lt;/p&gt;

&lt;p&gt;This Dockerfile is a multi-stage build. By default, the last image defined in
the Dockerfile is all that ends up being tagged. It’s what you ship to your
users, or upload to a Docker image repository. The other image(s) are simply
utilities used in the construction of the final image.&lt;/p&gt;

&lt;p&gt;The first image contains an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ADD&lt;/code&gt; statement that downloads the desired file.
This file is added to a layer in the “downloads” stage, but since this layer
isn’t part of the final stage or image, that’s fine; it’s just thrown away
later.&lt;/p&gt;

&lt;p&gt;The second image mounts part of the filesystem of the first image. This allows
it to access those files via the filesystem in a standard way, but doesn’t
actually add those files to the image itself. As an analogy, compare this to a
system mounting a network filesystem; the files can be accessed on the system,
but aren’t actually stored on the system. Thus, we can access the package to
run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dpkg -i&lt;/code&gt; on it, but don’t end storing it anywhere in the final image’s
filesystem. The exact parameters are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type=bind&lt;/code&gt;: Bind-mount a portion of another stage’s filesystem.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;from=downloader&lt;/code&gt;: The stage to mount from.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source=/downloads&lt;/code&gt;: The directory in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;from&lt;/code&gt; stage to mount.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target=/downloads&lt;/code&gt;: The directory to mount the directory onto when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUN&lt;/code&gt;ning
the command.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;making-it-work&quot;&gt;Making it work&lt;/h1&gt;

&lt;p&gt;A couple actions must be taken to make this all work.&lt;/p&gt;

&lt;p&gt;First, this relies on buildkit. You will probably need to explicitly enable
this by setting environment variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DOCKER_BUILDKIT=1&lt;/code&gt; when running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker
build&lt;/code&gt;. Apparently &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker buildx&lt;/code&gt; does this automatically if that command is
available in your Docker version.&lt;/p&gt;

&lt;p&gt;Second, you must tell Docker that you want to use new syntax. Place the
following text at the start of your Dockerfile:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;# syntax=docker/dockerfile:1.2&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That tells Docker how to parse the Dockerfile. Specifically, it tells Docker to
acquire a container named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker/dockerfile&lt;/code&gt; with version/tag 1.2 in order to
parse the Dockerfile.&lt;/p&gt;

&lt;h1 id=&quot;links&quot;&gt;Links&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://pythonspeed.com/articles/docker-buildkit/&quot;&gt;https://pythonspeed.com/articles/docker-buildkit/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hub.docker.com/r/docker/dockerfile/&quot;&gt;https://hub.docker.com/r/docker/dockerfile/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2021-03-02T00:00:00-07:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2021/03/02/1-avoiding-docker-add-copy-layers.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2021/03/02/1-avoiding-docker-add-copy-layers.html</guid>
        </item>
      
    
      
        <item>
          <title>VSCode Ctrl-scrolling</title>
          <description>&lt;p&gt;I’m trying out vscode for editing, since it has a nice “file explorer”
capability that I don’t get (at least by default) with GVim. However, the
scrolling behaviour annoyed me. But I found a solution!&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-issue&quot;&gt;The Issue&lt;/h1&gt;

&lt;p&gt;I typically use the cursor keys to scroll in my editor. Often, I want the
cursor to stay on the same line of code while the window scrolls. This allows
me to see more context above or below the location I’m editing without losing
my place (cursor position). In many editors, you get this behaviour by holding
down the Ctrl key while pressing the cursor key. Even when I don’t explicitly
care about keeping my cursor on the same line of code, holding Ctrl has the
advantage of immediately scrolling the view, rather than having to wait until
the cursor reaches to top/bottom line of the window. Consequently, I’m not in
the habit of “Ctrl-scrolling” more often than not.&lt;/p&gt;

&lt;p&gt;The question is: What happens when the line of code that contains the cursor
disappears off the screen? Some editors will move the cursor to a different
line of text in order to keep it on the screen. That’s the behaviour I like.
However, some editors will keep the cursor on the same line of text, even if
that line is no longer visible on screen. In this case, once you stop
Ctrl-scrolling and switch back to typing new text, or scrolling without Ctrl
pressed, the editor will snap the scroll position back so that the cursor is
still visible. I find this behaviour really annoying, since I typically
Ctrl-scroll just to find text I’m interested in, and actively want to cursor to
move there rather than preserving the cursor position.&lt;/p&gt;

&lt;h1 id=&quot;the-solution&quot;&gt;The Solution&lt;/h1&gt;

&lt;p&gt;VSCode’s keybindings can be customized to work the way I want:-) I found the
solution in the following github issue comment:&lt;/p&gt;

&lt;p&gt;https://github.com/microsoft/vscode/issues/2091&lt;/p&gt;

&lt;p&gt;To apply that solution, select File menu -&amp;gt; Preferences -&amp;gt; Keyboard Shortcuts
(or press Ctrl-K Ctrl-S). This will open the regular keyboard shortcuts editor.
From there, to manually edit keybindings, look for a button in the top-right of
the editor with tool-tip “Open Keyboard Shortcuts (JSON)” and click it. It looks
like a tiny document with an arrow pointing into it. That will open a JSON file
that you can edit. Paste in the following content and save it. You don’t even
need to restart VSCode for the modification to take effect! For more
information, see https://code.visualstudio.com/docs/getstarted/keybindings.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[
	{
		&quot;key&quot;: &quot;ctrl+up&quot;,
		&quot;command&quot;: &quot;editorScroll&quot;,
		&quot;when&quot;: &quot;editorTextFocus&quot;,
		&quot;args&quot;: 
		{
			&quot;to&quot;: &quot;up&quot;,
			&quot;by&quot;: &quot;line&quot;,
			&quot;revealCursor&quot;: true
		}
	},
	{
		&quot;key&quot;: &quot;ctrl+down&quot;,
		&quot;command&quot;: &quot;editorScroll&quot;,
		&quot;when&quot;: &quot;editorTextFocus&quot;,
		&quot;args&quot;: 
		{
			&quot;to&quot;: &quot;down&quot;,
			&quot;by&quot;: &quot;line&quot;,
			&quot;revealCursor&quot;: true
		}
	}
]&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

</description>
          <pubDate>2021-03-02T00:00:00-07:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2021/03/02/0-vscode-ctrl-scrolling.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2021/03/02/0-vscode-ctrl-scrolling.html</guid>
        </item>
      
    
      
        <item>
          <title>Ubuntu 20.04 lightdm black background</title>
          <description>&lt;p&gt;I’m very much a fan of black or at least plain backgrounds on my system;
there’s much less clutter and distraction. When I upgraded my laptop to Ubuntu
20.04, I naturally configure my user session’s background to plain black.
However, the login screen insisted on displaying some image rather than the
plain black I wanted. Here’s how I fixed this.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-user-image&quot;&gt;The User Image&lt;/h1&gt;

&lt;p&gt;Each user account has a wallpaper image selected, even if the user has selected
to use a plain color for their wallpaper when logged in. lightdm displays this
image by default, based on which user is in the process of logging in, rather
than honoring the user’s plain color selection for the wallpaper.&lt;/p&gt;

&lt;h1 id=&quot;the-expected-fix&quot;&gt;The Expected Fix&lt;/h1&gt;

&lt;p&gt;A quick Google search indicated that I should be able to edit
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/lightdm/lightdm-gtk-greeter.conf&lt;/code&gt; and set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background=#000000&lt;/code&gt;. However,
this didn’t work; the user wallpaper image continued to be displayed.&lt;/p&gt;

&lt;h1 id=&quot;the-actual-fix&quot;&gt;The Actual Fix&lt;/h1&gt;

&lt;p&gt;Option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user-background = false&lt;/code&gt; must be set so that the user’s wallpaper image
isn’t displayed.&lt;/p&gt;

&lt;p&gt;I ended up with the following &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/lightdm/lightdm-gtk-greeter.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[greeter]
background = #000000
icon-theme-name = Adwaita
font-name = Noto Sans 12
user-background = false
hide-user-image = true&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Subsequently to tracking down the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user-background&lt;/code&gt; option, I discovered that
this option can be selected via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lightdm-gtk-greeter-settings&lt;/code&gt; GUI tool;
it’s the “Use user wallpaper if available” option. Under XFCE at least, the
tool is available via Applications Menu ⇨ Setting Manager ⇨ LightDM GTK+
Greeter settings.&lt;/p&gt;
</description>
          <pubDate>2020-06-09T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2020/06/09/ubuntu-20.04-lightdm-black-background.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2020/06/09/ubuntu-20.04-lightdm-black-background.html</guid>
        </item>
      
    
      
        <item>
          <title>Ubuntu 20.04 xchat vs. 16.04 bip</title>
          <description>&lt;p&gt;I have an Ubuntu 16.04 server that runs the bip IRC proxy. Until recently, I
was happily accessing bip from an Ubuntu 18.04 laptop. However, when I upgraded
my laptop to Ubuntu 20.04, xchat refused to connect. This post describes how I
fixed that.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-error&quot;&gt;The Error&lt;/h1&gt;

&lt;p&gt;xchat would display the following:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;Connection failed. Error: (337260938) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Apparently the version of OpenSSL in Ubuntu 20.04 refuses to connect to servers
that use DH parameters that are too small. xchat uses OpenSSL to connect to
TLS-enabled servers. The ideal fix would be to configure bip to use larger or
custom DH parameters. However, the version of bip in Ubuntu 16.04 doesn’t allow
this; it generates the DH parameters internally with no way to override them:-(&lt;/p&gt;

&lt;h1 id=&quot;the-fix&quot;&gt;The Fix&lt;/h1&gt;

&lt;p&gt;Instead of terminating the TLS session using bip itself, I reconfigured bip to
listen on a different port on localhost in plain-text, and installed stunnel4
to terminate the TLS session and proxy it to bip.&lt;/p&gt;

&lt;h2 id=&quot;bip-configuration&quot;&gt;Bip Configuration&lt;/h2&gt;

&lt;p&gt;Original &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/bip.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;ip = &quot;0.0.0.0&quot;;
port = 8667;
client_side_ssl = true;
client_side_ssl_pem = &quot;/etc/ssl/current/avon.wwwdotorg.org.key-and-crt&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;New &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/bip.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;ip = &quot;127.0.0.1&quot;;
port = 8668;
client_side_ssl = false;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;To restart it:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;service bip restart&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;stunnel-configuration&quot;&gt;Stunnel Configuration&lt;/h2&gt;

&lt;p&gt;Create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/stunnel/wdo.conf&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;[bip]
accept = 8667
connect = 127.0.0.1:8668
cert = /etc/ssl/current/avon.wwwdotorg.org.crt-and-bundle
key = /etc/ssl/current/avon.wwwdotorg.org.key&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;To install stunnel:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;stunnel4&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;To enable it, edit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/default/stunnel4&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Original:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;ENABLED=0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Modified:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;ENABLED=1&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;To enable and stunnel:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;stunnel4 &lt;span class=&quot;c&quot;&gt;# May be the default?&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;service stunnel4 start&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

</description>
          <pubDate>2020-06-09T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2020/06/09/ubuntu-20.04-hexchat-vs-16.04-bip.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2020/06/09/ubuntu-20.04-hexchat-vs-16.04-bip.html</guid>
        </item>
      
    
      
        <item>
          <title>Why sudo cd doesn&apos;t work</title>
          <description>&lt;p&gt;The question of “why doesn’t &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo cd&lt;/code&gt; work?” has come up a couple times in the
last few weeks. I figured that the explanation would make for an interesting
blog post.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;what-shells-do&quot;&gt;What Shells Do&lt;/h1&gt;

&lt;p&gt;(Interactive) shells repeatedly prompt the user to type in a command-line, and
then attempt to execute that command-line. Once that command exits, the cycle is
repeated. The big question is: what does execute mean? The first
whitespace-separated word in the entered string is the command, and the rest of
the words are the arguments. Most commands are either the name of an executable
file, or the name of a built-in command. There are a few other possibilities such
as aliases and function names, but they aren’t relevant to this explanation.&lt;/p&gt;

&lt;h2 id=&quot;executable-files&quot;&gt;Executable Files&lt;/h2&gt;

&lt;p&gt;Executable files are stored on disk, typically in directories such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/bin&lt;/code&gt;,
or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin&lt;/code&gt;. Whenever the shell executes such a command, it searches for the
file in the current &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$PATH&lt;/code&gt;, and then creates a new process to run that file,
passing the arguments to the command.&lt;/p&gt;

&lt;h2 id=&quot;built-in-commands&quot;&gt;Built-in Commands&lt;/h2&gt;

&lt;p&gt;Some commands are so common or simple that the shell contains a built-in
implementation of the command. Other commands have to be built-in simply to
operate correctly. Examples of built-ins are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echo&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;built-in-or-external&quot;&gt;Built-in or External?&lt;/h2&gt;

&lt;p&gt;At least in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bash&lt;/code&gt;, you can determine whether a command is an executable file,
a built-in, or something else using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type&lt;/code&gt; command:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type ls
ls &lt;/span&gt;is /bin/ls

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type cd
cd &lt;/span&gt;is a shell built-in&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You can also use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;which&lt;/code&gt; to determine if or where a given executable exists on
disk:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;which &lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt;
/bin/ls&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;process-state&quot;&gt;Process State&lt;/h1&gt;

&lt;p&gt;Every process has certain state associated with it. Examples are the process
ID, ulimit configuration, and the current working directory. This state is
generally not shared between processes, and state changes in one process do not
affect any other process, even parent or child processes.&lt;/p&gt;

&lt;p&gt;When a new process is created, the child process’s state is initially a copy of
the parent process. The child process can then modify the state if desired and
permissions allow it (e.g. ulimit or nice values often can’t be changed in
certain ways). Such changes to the child process’s state do not affect the
parent process. When a process exits, all aspects of its state are destroyed,
and have no lasting effect. Of course, if a process makes changes to objects
other than its own state, such as to files on disk, those changes are preserved
even after the process exists; only a process’s own state is destroyed when a
process exits.&lt;/p&gt;

&lt;h1 id=&quot;current-working-directory&quot;&gt;Current Working Directory&lt;/h1&gt;

&lt;p&gt;Let’s consider what the current working directory of a process is used for.
Users can specify paths (e.g. in command-line arguments or a request for an
editor to open or save a file) in two forms; absolute and relative.&lt;/p&gt;

&lt;p&gt;Absolute paths, those beginning with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin&lt;/code&gt;, are meaningful as
written since they refer directly to the desired file.&lt;/p&gt;

&lt;p&gt;Relative paths are meaningless without stating where those paths are relative
to. The current working directory is the directory against which any relative
path name is resolved. For example, the relative path &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lib/i386-linux-gnu&lt;/code&gt; would
refer to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/lib/i386-linux-gnu&lt;/code&gt; if the current working directory was &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt;, or
would refer to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/lib/i386-linux-gnu/&lt;/code&gt; if the current working directory was
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr&lt;/code&gt;.&lt;/p&gt;

&lt;h1 id=&quot;the-cd-built-in&quot;&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; Built-in&lt;/h1&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; command changes the value of the current working directory of the
current process.&lt;/p&gt;

&lt;p&gt;What if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; were an executable file rather than a built-in? The shell would
have to execute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; as a new process. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; would change the current working
directory value for its own process; a state change that would not affect any
other process. Then, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; would exit, and the shell would prompt the user for
another command. Overall, these steps wouldn’t have any side-effects; in
particular, the current working directory value of the shell would not have
changed. This means that a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; executable file wouldn’t be that useful. For
this reason, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; must be a built-in command within the shell, so that it
affects the shell’s process state.&lt;/p&gt;

&lt;h2 id=&quot;cd-executable-in-hp-ux&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; Executable in HP-UX&lt;/h2&gt;

&lt;p&gt;An interesting piece of Unix trivia: Some versions of HP-UX do actually contain
a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin/cd&lt;/code&gt; executable file. This doesn’t seem very useful on the surface.
One potential use I’ve seen proposed is to test whether a path name is a valid
target for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; without affecting the current process’s state, e.g.:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; /usr/bin/cd /non/existent/path &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo yes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;no&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fi
&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;no

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; /usr/bin/cd /usr/lib &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo yes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;no&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fi
&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo yes&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;what-sudo-does&quot;&gt;What &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; Does&lt;/h1&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; is a setuid program which allows running commands as a different user ID.
For example, if given permission by a system administrator, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; may allow
certain unprivileged users to run specific commands as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;. This is commonly
used to allow such users to perform specific limited system administration
duties, or if people simply want to hack around permissions issues!&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; is an executable file and not a shell built-in. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; therefore runs as
a separate process to the shell, and always creates a new process to run the
user-specified command; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; has no built-ins that are run in-process.&lt;/p&gt;

&lt;p&gt;An example of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; usage:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt; /root
&lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt;: cannot open directory &lt;span class=&quot;s1&quot;&gt;&apos;/root&apos;&lt;/span&gt;: Permission denied

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo ls&lt;/span&gt; /root
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; password &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;swarren: 
some
files&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;putting-it-all-together&quot;&gt;Putting it All Together&lt;/h1&gt;

&lt;p&gt;A simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; command is executed directly by the shell, and hence affects the
shell’s own state.&lt;/p&gt;

&lt;p&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo cd&lt;/code&gt; command attempts to run a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; executable. Since this typically
doesn’t exist, this will typically fail as:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo cd&lt;/span&gt; /root
&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;command &lt;/span&gt;not found&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Should a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; executable actually exist, and actually implement a “change
working directory” operation, it still wouldn’t do what we want, since it would
only change the current working directory for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd&lt;/code&gt; process itself, which
would not affect either the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; or shell parent processes.&lt;/p&gt;

&lt;h1 id=&quot;credits&quot;&gt;Credits&lt;/h1&gt;

&lt;p&gt;Aaron Johnson for the information about the HP-UX &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin/cd&lt;/code&gt; executable.&lt;/p&gt;

&lt;p&gt;Bob Proulx for review of this blog post. All mistakes are mine though!&lt;/p&gt;

&lt;h1 id=&quot;changelog&quot;&gt;Changelog&lt;/h1&gt;

&lt;p&gt;2017/09/26: Typo.&lt;/p&gt;
</description>
          <pubDate>2017-09-26T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2017/09/26/why-sudo-cd-does-not-work.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2017/09/26/why-sudo-cd-does-not-work.html</guid>
        </item>
      
    
      
        <item>
          <title>ESP8266 Garage Door Controller</title>
          <description>&lt;p&gt;The ESP8266 micro-controller makes a great Internet-of-Things device. It’s
cheap, easy to use (especially via the Arduino IDE), and has been quite
reliable for me. Here’s a description of how I used one to allow remote
control of my garage door via the Internet.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;description&quot;&gt;Description&lt;/h1&gt;

&lt;p&gt;My primary motivation for create a WiFi/IOT garage door opener was that I store
my bicycle in the garage, but don’t keep a garage door remote in my backpack, so
often had to go back and get the remote after getting my bike out of the house.
However, I always carry my phone, so if I could use that instead, I would no
longer have a problem controlling the garage door. Since the project worked so
well, I installed it on my other garage door, which was lucky since I purchased
a new car that didn’t have an integrated garage door remote, so I now use my
phone to close/open the door every time I leave or come home.&lt;/p&gt;

&lt;p&gt;Here’s how the project looks installed:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-04-18-esp8266-garage-door/installed.jpg&quot; alt=&quot;Project installed&quot; title=&quot;Project installed&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As you can tell, I used a NodeMCU ESP8266 board for the web interface, created
a custom PCB to mount that board to the wall and provide connectors for the
other components, used a relay board to interface with the existing garage door
opener, and added ultrasound sensors to enable reporting the position of the
door.&lt;/p&gt;

&lt;h1 id=&quot;project-files&quot;&gt;Project Files&lt;/h1&gt;

&lt;p&gt;You can find all source code and design files for this project in my
&lt;a href=&quot;https://github.com/swarren/esp8266-garage-door&quot;&gt;github repo&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;esp8266-software&quot;&gt;ESP8266 Software&lt;/h1&gt;

&lt;p&gt;The ESP8266 supports a few different software stacks. One of which is the
Arduino IDE. I chose this because it’s extremely simple to use, works similarly
across a variety of hardware, and the ESP8266 board support comes with a slew of
simple libraries allowing control over the WiFi configuration, management of
filesystems in flash, and serving a website including pretty easy form/POST
handling.&lt;/p&gt;

&lt;p&gt;The ESP8266 hosts a website with just one page that contains buttons to activate
each connected garage door; the software supports either 1 or 2 doors. Each
button is a simple HTML form that HTTP POSTs back to the server to activate a
door, which then re-directs the user back to the same page in case they want to
activate the door again later. Each door is controlled using a single GPIO
output signal that connects to a relay, which simply shorts the wires that are
otherwise connected to the “manual” push button that controls the door. This
method of interfacing with the door controller minimizes the possibility of
interfering with the existing electronics in any way; the motor system can’t
tell whether a human or a device “pressed the button”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-04-18-esp8266-garage-door/web-ui.png&quot; alt=&quot;Web User
Interface&quot; title=&quot;Web User Interface&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The software has a few features beyond this basic operation:&lt;/p&gt;

&lt;h2 id=&quot;wifi-setup&quot;&gt;WiFi Setup&lt;/h2&gt;

&lt;p&gt;WiFi configuration is stored in a file in a flash-based filesystem. If this file
is missing, the ESP8266 will act as a WiFi base station with obvious ESSID and
known password. This allows the user to connect using a web browser and provide
credentials for the WiFi network that the device should connect to. Once
entered, the device will connect to the specified network, at which point the
user can confirm the settings and save them to flash. The user can clear the
settings by holding a push button for 10 seconds, which can be useful when
moving the device to another WiFi network, or for testing the configuration
setup mechanism. The implementation is extremely basic at present; just enough
to make the system work, but not pretty or flashy.&lt;/p&gt;

&lt;h2 id=&quot;door-state-sensing&quot;&gt;Door State Sensing&lt;/h2&gt;

&lt;p&gt;I figured that a WiFi door remote should report the position of the door as well
as trigger it to open and close. I didn’t want to hook into the existing motor
limit switches for this purpose, to avoid interfering with the existing
electronics in any way. I decided to use an HC-SR04 ultrasound range sensor for
this purpose. I attached (half of) an old plastic ruler to the door’s lock/latch
pin (using cable ties and hot glue!) as an ultrasound reflector, and made sure
this stuck out from the side of the door. I mounted the HC-SR04 on the wall
behind it. When the door is closed, the ultrasound range is about 10cm, and when
open it’s tens of feet to the other side of the garage, which is probably
counted as “no reflection” or “maximum range” by the sensor. The software pings
the ultrasound every few seconds, applies a little hysteresis to avoid any
measurement fluctuations, and reports the status in the main web page.&lt;/p&gt;

&lt;p&gt;The one quirk here was that the ultrasound sensor output a 5V logic signal,
whereas the ESP8266 GPIO inputs are technically only rated for 3.3V. To solve
this, I used a simple voltage divider between the ultrasound output and the
ESP8266 GPIO pin to lower the signal voltage.&lt;/p&gt;

&lt;p&gt;One cunning aspect of the ultrasound logic is its used of interrupts to measure
the length of the echo pulse. This avoids any kind of busy loop to measure the
echos, which allows the system to quickly respond to network packets all the
time.&lt;/p&gt;

&lt;h2 id=&quot;hostname-discovery&quot;&gt;Hostname Discovery&lt;/h2&gt;

&lt;p&gt;The device runs both MDNS and LLMNR to allow systems attached to the local
network to dynamically convert “.local” hostnames to IP addresses. this allows
the device to be found without requiring manually created DNS entries, or
servers for dynamic DNS such as dyndns. This combination of protocols works
great from Linux, Windows, and MacOS. However, Android doesn’t seem to support
any of them:-( I resorted to using an application named “Pea Finder”, which
implements MDNS and can launch a web browser for any discovered device.&lt;/p&gt;

&lt;h2 id=&quot;exposing-to-the-internet&quot;&gt;Exposing to the Internet&lt;/h2&gt;

&lt;p&gt;The ESP8266 software doesn’t implement any form of authentication. I figure that
anyone connected to my WiFi is probably already in the house, or could break in
if they wanted anyway. However, I could imagine checking the door status
remotely, and thus Internet access was desirable. I certainly wasn’t going to
just port-forward the ESP8266 to the Internet and let any old script kiddy
port-scan their way to control of my garage door. To address the security issue
while still allowing Internet access, I made my existing Linux home server
reverse-proxy HTTP requests from the Internet to the ESP8266, while requiring
authentication to access those URLs. Here are the relevant parts of the Apache
configuration:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-apache&quot; data-lang=&quot;apache&quot;&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;VirtualHost&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; *:443&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;SSLEngine&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;on&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;SSLCertificateFile&lt;/span&gt; /path/to/severn.wwwdotorg.org.crt
    &lt;span class=&quot;nc&quot;&gt;SSLCertificateKeyFile&lt;/span&gt; /path/to/severn.wwwdotorg.org.key
    &lt;span class=&quot;nc&quot;&gt;SSLCertificateChainFile&lt;/span&gt; /path/to/severn.wwwdotorg.org.ca-bundle
&lt;span class=&quot;err&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Location&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;
&lt;/span&gt;        &lt;span class=&quot;nc&quot;&gt;AuthType&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;Basic&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;AuthName&lt;/span&gt; &quot;severn.wwwdotorg.org&quot;
        &lt;span class=&quot;nc&quot;&gt;AuthBasicProvider&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;file&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;AuthUserFile&lt;/span&gt; &quot;/path/to/passwd&quot;
        &lt;span class=&quot;nc&quot;&gt;AuthGroupFile&lt;/span&gt; &quot;/path/to/group&quot;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Location&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /garage-door-main/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;
&lt;/span&gt;        &lt;span class=&quot;nc&quot;&gt;Require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;group&lt;/span&gt; garage_door
        &lt;span class=&quot;nc&quot;&gt;ProxyHTMLEnable&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;On&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;ProxyHTMLURLMap&lt;/span&gt; / /garage-door-main/
        &lt;span class=&quot;nc&quot;&gt;ProxyPass&lt;/span&gt; &quot;http://garage-door-main.local/&quot;
        &lt;span class=&quot;nc&quot;&gt;ProxyPassReverse&lt;/span&gt; &quot;/&quot;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;VirtualHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;simple-android-shortcuts&quot;&gt;Simple Android Shortcuts&lt;/h2&gt;

&lt;p&gt;While opening a web browser to control the door is pretty quick, I wanted
something even faster; something close to the speed of a dedicated garage door
remote. My current car has bluetooth, so I set my phone to stay unlocked when in
the car, which speeds up access - typically I have to unlock it via a PIN code
every time I use it. I used an application named “Tasker” to create a task for
each garage door, which simply performs the “activate door N” password-protected
HTTP POST to the Internet-visible site, and created a desktop icon/shortcut for
each task. Opening a door is easy now; press the power button to turn on the
screen, swipe up to “unlock” the phone, and click/touch a single icon on the
home screen. The only issue is that when I leave the house, the phone is slow to
disconnect from WiFi when the signal drops, so sometimes I have to manually
disconnect WiFi first. I expect Tasker can automate disabling WiFi as part of a
task’s actions, so I’ll look into that in the near future.&lt;/p&gt;

&lt;h1 id=&quot;kicad-pcb&quot;&gt;Kicad PCB&lt;/h1&gt;

&lt;p&gt;My first prototype system hung the ESP8266 from a nail in the wall by the 5V USB
power cable. Wiring was manual point-to-point using individual wires. This
worked, but was messy.&lt;/p&gt;

&lt;p&gt;The ESP8266 board does have some mounting holes, but they’re pretty tiny. A
better mounting solution was needed; one with larger holes. I also wanted to
provide nicely laid out dedicated connectors for the ultrasound sensors and
relay board, rather than having to connect all the pins one-by-one into various
wiring harnesses. Finally, constructing the ultrasound voltage divider inline
with a wiring harness was a bit annoying.&lt;/p&gt;

&lt;p&gt;I ended up creating a PCB in Kicad; the first real use I’ve made of Kicad.
Ordering the PCB from oshpark.com was a breeze since they now allow direct
upload of Kicad PCB files:-)&lt;/p&gt;

&lt;h1 id=&quot;ultrasound-mounts&quot;&gt;Ultrasound Mounts&lt;/h1&gt;

&lt;p&gt;The ultrasound sensors also needed mounting on the wall. A custom PCB wasn’t the
answer here, since the ultrasound boards have a right-angle connector which
couldn’t easily plug into a PCB that was mounted flat to the wall. Instead, I
designed a simple plastic mount the encapsulate the sensor, and attached that to
the wall.&lt;/p&gt;

&lt;p&gt;On my main garage doors, I wanted to point the ultrasound straight out from the
wall, and reflects off a ruler sticking out from door as I described above. On
my third garage door, I plan to mount the ultrasound sensor so the sound travels
parallel to the wall and reflects off the side of the door. Rather than design
two different mounts for these two configurations, I designed a single primary
mount that encapsulates the ultrasound sensor, and two different sets of flanges
that glue to the end of the mount, and allow the mount to be attached to the
wall at different 90 degree angles. I also designed a small clip that tightly
fits over the front of the mount and the ultrasound PCB and holds everything
tightly in place.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-04-18-esp8266-garage-door/hcsr04-mounts.jpg&quot; alt=&quot;Ultrasound mounts&quot; title=&quot;Ultrasound mounts&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;mistakes&quot;&gt;Mistakes&lt;/h1&gt;

&lt;p&gt;As I mentioned in a previous blog post, I chose the wrong ESP8266 GPIOs for the
relay control; when power is first applied to the board, some of the GPIOs
glitch, and for just long enough to trigger the relays and cause the door to
open. This is fine when I’m standing next to the garage doors installing the
system, but I didn’t fancy that happening during a power outage when I might not
be home. Consequently, I worked out which GPIOs had this problem and which
didn’t, and designed a rev 2 PCB to avoid connecting the problematic GPIOS to
the relays. The new PCBs should arrive in a few days, so I’ll soon be able to
tell if this problem is fixed!&lt;/p&gt;

&lt;h1 id=&quot;future-work&quot;&gt;Future Work&lt;/h1&gt;

&lt;p&gt;I have some ESP8266 projects that have been running for months or even years
without issue. However, I noticed just today that my garage door controller
wasn’t responding correctly so I had to reset it. Some kind of automated
watchdog or periodic reboot might be a good idea.&lt;/p&gt;

&lt;p&gt;The WiFi setup in my code works, but is extremely rudimentary. It only allows
the device to operate in station mode (not as an access point) after setup.
If I re-write the software, I’ll investigate any existing ESP8266 WiFi manager
projects. I didn’t look for one when I first created the project because I
(a) wanted to create the whole project myself the first time around, and (b)
wanted to hack it into existence as quickly as possible, without getting
bogged down integrating 3rd-party code.&lt;/p&gt;

&lt;p&gt;The user interface (web pages) are very bland. Some style-sheets and AJAX
would improve the user-experience a lot.&lt;/p&gt;

&lt;p&gt;Sometimes the garage door will just “open itself”. This happened before I
implemented the ESP8266 system, so I suspect it’s a matter of wireless noise
accidentally triggering the existing door opener protocol. I’d like the ESP8266
to email me whenever the door opens or closes, or perhaps any time it’s been
open for more than some duration such as 5 minutes.&lt;/p&gt;

&lt;p&gt;The current software hard-codes the set of GPIOs and door names. I’d like to
store this information in a configuration file in the flash filesystem instead,
and allow editing of the pin assignments via the web. With a bit of work, this
could turn into a generic ESP8266 web-based GPIO control system, not just
something for garage doors.&lt;/p&gt;

&lt;h1 id=&quot;bill-of-materials&quot;&gt;Bill of Materials&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;NodeMCU ESP8266 board. This is available for $8-$10 on Amazon.com from a
variety of sellers. For example:
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B01IK9GEQG/ref=oh_aui_detailpage_o05_s00?ie=UTF8&amp;amp;psc=1&quot;&gt;Makerfocus Amazon link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B010O1G1ES/ref=oh_aui_detailpage_o07_s02?ie=UTF8&amp;amp;psc=1&quot;&gt;HiLetgo Amazon link&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;

    &lt;p&gt;Note: These are cheap devices without much markup. As such, you’ll probably
see quality issues on some devices. Order a few more than you need and
everything will work out. The good thing is that Amazon has easy returns or
replacements, and free Prime shipping from at least the sellers linked above.
I prefer the NodeMCU board to the Adafruit Huzzah because it’s got built-in
USB-serial, plus is a tad cheaper and ships faster/cheaper.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;USB 5v power supply or charger.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;TTL-controlled relay board. Again I got this from Amazon via the link below.
I’m sure there are plenty of other similar devices available.
&lt;a href=&quot;https://www.amazon.com/gp/product/B00TGUH99U/ref=oh_aui_search_detailpage?ie=UTF8&amp;amp;psc=1&quot;&gt;Amazon link&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;HC-SR04 ultrasound transceivers.
&lt;a href=&quot;https://www.amazon.com/gp/product/B01COSN7O6/ref=oh_aui_detailpage_o09_s00?ie=UTF8&amp;amp;psc=1&quot;&gt;Amazon link&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Various 0.1” connectors and wires that I had hanging around.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;PCB ordered from oshpark.com.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;3D-printed HC-SR04 mounts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;changelog&quot;&gt;Changelog&lt;/h1&gt;

&lt;p&gt;2017/04/21: Change code highlighter to pygments; rouge elides some Apache
keywords.&lt;/p&gt;

&lt;p&gt;2017/04/25: Simplified Apache reverse proxy configuration snippet.&lt;/p&gt;
</description>
          <pubDate>2017-04-18T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2017/04/18/esp8266-garage-door.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2017/04/18/esp8266-garage-door.html</guid>
        </item>
      
    
      
        <item>
          <title>ESP8266 GPIO Behaviour at Boot</title>
          <description>&lt;p&gt;I recently connected my garage door to the Internet using an ESP8266. More on
that topic in another post. This post covers some research I did after
discovering that one of my garage doors opened every time the power was
removed from the ESP8266 and re-applied.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;background&quot;&gt;Background&lt;/h1&gt;

&lt;p&gt;My WiFi garage door opener is simply a pair of relays connected to ESP8266
GPIOs. I essentially chose which specific GPIO pins to use at random; D0 and
D5. The relays are triggered by a high logic level, which I naively assumed
would be safest, since a non-operational ESP8266 wouldn’t trigger them.
Evidently there are some glitches on the ESP8266 GPIOs when it is first powered
on, since one of the relays does trigger for a short time when the system is
powered on. I set out to capture the ESP8266 GPIO signals, first using a logic
analyzer, and later using an oscilloscope.&lt;/p&gt;

&lt;h1 id=&quot;investigation&quot;&gt;Investigation&lt;/h1&gt;

&lt;p&gt;Note: Most of this post uses NodeMCU’s GPIO numbering, which is different than
ESP8266 raw GPIO numbering.&lt;/p&gt;

&lt;p&gt;I started out by capturing the state of the two relevant ESP8266 GPIO pins
using a logic analyzer. This showed no difference in behaviour; both pins
started low while the ESP8266 was powered off, then briefly pulsed high while
the ESP8266 booted, then returned low when my Arduino application began to run
and explicitly set the GPIOs to output a low value:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_boot_arduino_all_gpio_out_low.jpg&quot; alt=&quot;ESP8266 GPIO behaviour at arduino_set_low boot&quot; title=&quot;ESP8266 GPIO digital behaviour at boot; Arduino app setting all GPIOs low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 GPIO digital behaviour at boot, when running a simple Arduino application that does nothing except to set all GPIOs to output a low value at boot.&lt;/p&gt;

&lt;p&gt;This behaviour was puzzling since the two relays in the system were identical,
yet only one actually triggered. Swapping the ESP8266 GPIOs between the relays
showed that the behaviour followed the ESP8266 GPIO signal, and not the relay.
Hence, I set out to investigate the GPIO output behaviour in even more detail.
Viewing those GPIOs using a oscilloscope showed a difference; the D0 low output
level isn’t 0V, but rather about 1V, whereas D5’s low output value is 0V as
expected:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d0.jpg&quot; alt=&quot;ESP8266 GPIO D0 analog behaviour&quot; title=&quot;ESP8266 GPIO D0 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D0 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d5.jpg&quot; alt=&quot;ESP8266 GPIO D5 analog behaviour&quot; title=&quot;ESP8266 GPIO D5 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D5 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;I can only assume that D0’s higher low voltage keeps some capacitance in the
relay board charged just long enough to let the relay coil close the relay for
a short time, but this soon discharges, releasing the relay again. Evidently
the 1V level is below my digital logic analyzer’s Vih (Voltage input high)
level.&lt;/p&gt;

&lt;p&gt;After observing this strange behaviour, I set out to measure the digital
behaviour of all GPIO pins in three situations:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;When the ESP8266 is powered on in flashing/bootloader mode.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;When booting into a Arduino application that does literally nothing.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;When booting into an Arduino application that explicitly sets all GPIOs to
output a low value.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I also captured the behaviour of all GPIOs using an oscilloscope in case 3
above.&lt;/p&gt;

&lt;p&gt;The logic analyzer configuration includes the ESP8266 3V3 power rail as an
additional input signal, and are triggered by a rising edge of this signal.&lt;/p&gt;

&lt;p&gt;The oscilloscope traces were triggered by a rising edge of the individual GPIO
being measured.&lt;/p&gt;

&lt;h1 id=&quot;gpio-behaviour-summary&quot;&gt;GPIO Behaviour Summary&lt;/h1&gt;

&lt;p&gt;Here’s a summary of how all the ESP8266 GPIOs behave. Pictures of the
analyzer/scope traces are shown below.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;NodeMCU&lt;br /&gt;GPIO&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;ESP8266&lt;br /&gt;GPIO&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Behaviour&lt;br /&gt;Flash Mode&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Behaviour&lt;br /&gt;Dummy Arduino App&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Behaviour&lt;br /&gt;Arduino Set GPIOs Low&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;16&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High during boot, falls after ~110ms (to ~1V?)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High during boot, falls after ~110ms  (to ~1V)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D1&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low then oscillates&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Varies, stabilizes high after ~100ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Varies, stabilizes low after ~110ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D4&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Varies, stabilizes high after ~60ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Varies, stabilizes high after ~70ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Varies, stabilizes low after ~110ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;14&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High, then low after ~110ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High, then low after ~110ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D6&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;12&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High, then low after ~110ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High, then low after ~110ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D7&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;13&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High, then low after ~110ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High, then low after ~110ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D8&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;15&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low, with glitch ~110ms&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low, with glitch ~110ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D9&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low until ~50ms then high&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low until ~50ms then high until ~110ms then low&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;D10&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low until ~50ms then high&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low until ~50ms then high until ~110ms then low&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Conclusion: GPIOs D1 and D2 are the only safe GPIOs I can use to drive relays
if I don’t want them to operate autonomously at boot. I will have to rework my
PCB:-(&lt;/p&gt;

&lt;h1 id=&quot;future-work&quot;&gt;Future Work&lt;/h1&gt;

&lt;p&gt;I didn’t investigate GPIO behaviour in all possible cases. The following might
be interesting cases too:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;An Arduino application that explicitly sets all GPIOs to output a high value.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;An Arduino application that explicitly sets all GPIOs to input mode.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Native ESP8266 applications, i.e. not using the Arduino environment.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Analog behaviour with more than one type of application.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Compare multiple ESP8266 boards to see if the behaviour varies at all. I
suspect analog behaviour would be most interesting here.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Retest with a weak pull-up/-down attached to each GPIO, to verify whether
they’re floating randomly or actively driven by the ESP8266 at boot. In
most cases, I’m fairly sure they’re actively driven since the patterns are
repeatable. However, best to be sure. Suggested by Anders Sandblad.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;additional-information-from-erich-flach&quot;&gt;Additional Information from Erich Flach&lt;/h1&gt;

&lt;p&gt;In May 2018, I received an email from Erich Flach detailing an investigation
he’d performed into ESP8266 GPIO usage at boot time. Here’s what he wrote:&lt;/p&gt;

&lt;p&gt;Dear Stephen,&lt;/p&gt;

&lt;p&gt;Thank you for the information given on your website!
I’d like to add some explanations about the behaviour of
some pins:&lt;/p&gt;

&lt;p&gt;A year ago or so, I also investigated on the ESP8266 NodeMCU
boot behaviour since I tried to use as much IO as possible.
Unfortunately, I don’t have the diagrams etc. from that time,
but as far as I remember, I observed the following:&lt;/p&gt;

&lt;p&gt;GPIO1, i.e. “TX”, “TXD0”, and GPIO2, i.e. “D4”, “TXD1” have a somewhat
strange behaviour showing the following steps at startup:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Check level of line TXD0. If it is 1, continue with step 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Apply the internal pull up resistor to TXD0. If it becomes 1,
assume that the line is free. If it remains at 0, continue with step 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Send (useless) boot loader startup information on TXD0 and
continue startup process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Check level of line TXD1. If it is 1, stop everything (!).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Apply the internal pull up resistor to TXD1. If it becomes 1,
assume that the line is free. If it remains at 0, stop everything (!).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Send (useless) boot loader startup information on TXD1 and
continue startup process.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So in a few words: Try to send the startup information via TXD0,
or TXD1. If this is not possible, refuse to work.&lt;/p&gt;

&lt;p&gt;I was really annoyed by the fact that the processor stops to work
just because of the (for me) completely useless startup messages.
It was hard to believe that the implementation is so silly that it
refuses to continue when the lines are just occupied by some
external IO.&lt;/p&gt;

&lt;p&gt;If you want to check this, it’s rather easy to do by using medium-
resistance pull-down or pull-up resistors (22k, or so) to change
the line level. Then you may obeserve with the oscilloscope the
internal pull-up applied to the line before the data is sent.&lt;/p&gt;

&lt;h1 id=&quot;pictures&quot;&gt;Pictures&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_boot_flash_mode.jpg&quot; alt=&quot;ESP8266 GPIO behaviour at flash boot&quot; title=&quot;ESP8266 GPIO digital behaviour at boot; flash mode&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 GPIO digital behaviour at boot, with the device forced into flash mode (bootloader) at power on.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_boot_arduino_dummy.jpg&quot; alt=&quot;ESP8266 GPIO behaviour at arduino dummy_boot&quot; title=&quot;ESP8266 GPIO digital behaviour at boot; Arduino dummy app&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 GPIO digital behaviour at boot, when running a dummy Arduino application that does absolutely nothing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_boot_arduino_all_gpio_out_low.jpg&quot; alt=&quot;ESP8266 GPIO behaviour at arduino_set_low boot&quot; title=&quot;ESP8266 GPIO digital behaviour at boot; Arduino app setting all GPIOs low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 GPIO digital behaviour at boot, when running a simple Arduino application that does nothing except to set all GPIOs to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d0.jpg&quot; alt=&quot;ESP8266 GPIO D0 analog behaviour&quot; title=&quot;ESP8266 GPIO D0 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D0 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d1.jpg&quot; alt=&quot;ESP8266 GPIO D1 analog behaviour&quot; title=&quot;ESP8266 GPIO D1 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D1 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d2.jpg&quot; alt=&quot;ESP8266 GPIO D2 analog behaviour&quot; title=&quot;ESP8266 GPIO D2 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D2 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d3.jpg&quot; alt=&quot;ESP8266 GPIO D3 analog behaviour&quot; title=&quot;ESP8266 GPIO D3 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D3 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d4.jpg&quot; alt=&quot;ESP8266 GPIO D4 analog behaviour&quot; title=&quot;ESP8266 GPIO D4 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D4 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d5.jpg&quot; alt=&quot;ESP8266 GPIO D5 analog behaviour&quot; title=&quot;ESP8266 GPIO D5 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D5 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d6.jpg&quot; alt=&quot;ESP8266 GPIO D6 analog behaviour&quot; title=&quot;ESP8266 GPIO D6 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D6 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d7.jpg&quot; alt=&quot;ESP8266 GPIO D7 analog behaviour&quot; title=&quot;ESP8266 GPIO D7 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D7 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d8.jpg&quot; alt=&quot;ESP8266 GPIO D8 analog behaviour&quot; title=&quot;ESP8266 GPIO D8 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D8 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d9.jpg&quot; alt=&quot;ESP8266 GPIO D9 analog behaviour&quot; title=&quot;ESP8266 GPIO D9 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D9 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-28-esp8266-gpio/esp8266_scope_d10.jpg&quot; alt=&quot;ESP8266 GPIO D10 analog behaviour&quot; title=&quot;ESP8266 GPIO D10 analog behaviour at boot; Arduino app setting GPIO low&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Above: ESP8266 D10 GPIO analog behaviour at boot, when running a simple Arduino application that sets the GPIO to output a low value at boot.&lt;/p&gt;

&lt;h1 id=&quot;changelog&quot;&gt;Changelog&lt;/h1&gt;

&lt;p&gt;2019/05/22: Added info from Erich Flach.&lt;/p&gt;

&lt;p&gt;2017/04/03: Add “future work” item to re-test with external GPIO pull-ups/-downs.&lt;/p&gt;
</description>
          <pubDate>2017-03-28T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2017/03/28/esp8266-gpio.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2017/03/28/esp8266-gpio.html</guid>
        </item>
      
    
      
        <item>
          <title>PVC Pipe Scabbard</title>
          <description>&lt;p&gt;I recently purchased my own sword, for use at the &lt;a href=&quot;http://www.sca.org/&quot;&gt;SCA&lt;/a&gt;,
and built a scabbard for it. A scabbard serves two purposes; first as
protection for the blade while the sword is stored or in transit, and second it
can be used as a defensive weapon while fencing.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;the-completed-project&quot;&gt;The Completed Project&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-21-scabbard/inside.jpg&quot; alt=&quot;Scabbard holding sword&quot; title=&quot;Scabbard holding sword&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The completed scabbard holding my sword. The colors were chosen to match the
local Barony’s, along with a small (debatably period-appropriate) English flag.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-21-scabbard/beside.jpg&quot; alt=&quot;Scabbard beside sword&quot; title=&quot;Scabbard beside sword&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The scabbard beside my sword, showing that the scabbard length matches the
length of the blade, plus a small margin.&lt;/p&gt;

&lt;h1 id=&quot;brief-construction-instructions&quot;&gt;Brief Construction Instructions&lt;/h1&gt;

&lt;p&gt;This is a very simple project!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Place the PVC pipe next to your sword and mark a length that will allow the
blade to completely fit inside the scabbard. SCA rules require that any
scabbard used as a defensive weapon be no more than 2” longer than the blade.
However, if you’re only building this for sword storage or display, or other
purposed, feel free to select any length you want.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Cover one end of the pipe and the inside of the PVC cap with PVC glue, and
stick them together.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Deburr the cut end of the pipe using a file or similar tool. Burrs don’t look
great and could even be slightly sharp.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;I also filed down the PVC end cap to try and round out all the edges. I
couldn’t find one with a rounded end at the local hardware store, so did a bit
more filing/rounding than you might need.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For decorative purposes, and certainly for use as an SCA weapon, the entire
surface must be covered. I used 3 layers of electrical tape, which may not
actually be compliant with SCA rules. It’s best to put down at least 1 layer of
true duct tape or similar to act as a strong base layer, and then electrical
tape can be layered on top for finer decoration.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;bill-of-materials&quot;&gt;Bill of Materials&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;1” diameter PVC pipe, slightly longer than your sword’s blade. Note: If your
blade isn’t the same size as mine, you may want narrower or wider pipe.&lt;/li&gt;
  &lt;li&gt;Perhaps a hacksaw to cut the pipe to length.&lt;/li&gt;
  &lt;li&gt;PVC end cap.&lt;/li&gt;
  &lt;li&gt;PVC glue.&lt;/li&gt;
  &lt;li&gt;File to round of edges.&lt;/li&gt;
  &lt;li&gt;Lots of duct tape, electrical tape, etc.&lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2017-03-21T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2017/03/21/scabbard.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2017/03/21/scabbard.html</guid>
        </item>
      
    
      
        <item>
          <title>WS2812 Reading Light</title>
          <description>&lt;p&gt;Like many people, I often read in bed. However, my wife doesn’t really
appreciate me having the overhead lights on when she’s trying to sleep. I
decided to solve the issue by building a more targeted reading light. Here’s a
brief description of the project.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;project-description&quot;&gt;Project Description&lt;/h1&gt;

&lt;p&gt;I had plenty of WS2812 (programmable RGB) LED strips left over from other
projects, so these were the obvious light source, being readily to hand. These
LEDs are mounted on a thin flexible PCB, so I cut out a strip of cardboard
slightly larger than the LED strip and glued the LED strip onto it. This gave
the strip a more rigid structure. I then taped the cardboard strip to my bed’s
headboard, point downwards where I sleep. A later enhancement to the project
may to find a triangular strip of wood to back the LED strip, and permanently
install it using glue or screws; the duct tape tends to peel off a little and
needs to be manually pushed back into place. Here’s a look at a section of the
LED strip:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-17-ws2812-reading-light/strip-mounted.jpg&quot; alt=&quot;LED strip mounted&quot; title=&quot;LED strip mounted&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The LED strip needs to be controlled by some form of micro-controller; it needs
to be sent commands to configure each LED’s color and brightness. I had a
Sparkfun Arduino Pro Mini hanging around and selected that. Even though I’m
powering the LEDs with 5V, and this micro-controller is a 3.3V device, I found
the LEDs had no issue receiving and processing the commands.&lt;/p&gt;

&lt;p&gt;I mounted everything up in a small old cardboard box that probably housed some
electronic components that I’d ordered from a website long ago; very similar to
Sparkfun’s red cardboard project boxes. Here’s a look inside the project box:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-17-ws2812-reading-light/box-open.jpg&quot; alt=&quot;Project box internals&quot; title=&quot;Project box internals&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I used a switch to cut power to the Arduino. Whenever the
system is powered on, the Arduino simply turns on all LEDs to a low-brightness
white. Later, I intend to add some push-buttons to control brightness, color,
and/or the number of LEDs that are turned on. Perhaps I’ll even replace the
Arduino with an ESP8266 to allow WiFi control, but that’s probably going
overboard. Here’s a look at the box once it’s closed up and perched on top of
my alarm clock radio, with the wire to the LEDs taped along the rear corner of
the shelf:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-17-ws2812-reading-light/box-installed.jpg&quot; alt=&quot;Project box installed&quot; title=&quot;Project box installed&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Below is a picture of the system in the dark:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2017-03-17-ws2812-reading-light/strip-lit.jpg&quot; alt=&quot;LED strip lit&quot; title=&quot;LED strip lit&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;bill-of-materials&quot;&gt;Bill of Materials&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;5V USB charger&lt;/li&gt;
  &lt;li&gt;6’ USB power cable&lt;/li&gt;
  &lt;li&gt;DPDT switch&lt;/li&gt;
  &lt;li&gt;Small cardboard box&lt;/li&gt;
  &lt;li&gt;Arduino Mini Pro 328 3.3V&lt;/li&gt;
  &lt;li&gt;0.1” male headers for the Arduino.&lt;/li&gt;
  &lt;li&gt;A few wires for internal project box wiring. Wires with 0.1” female headers
are best since these can be plugged directly into the Arduino on one end,
while the connector on the other end can be cut off and the wire soldered
elsewhere.&lt;/li&gt;
  &lt;li&gt;A few feet of e.g. Ethernet cable, to connect the LED strip&lt;/li&gt;
  &lt;li&gt;WS2812 LED strip&lt;/li&gt;
  &lt;li&gt;LED strip power connector (JST SM 3-pin), one male and one female&lt;/li&gt;
  &lt;li&gt;Cardboard backing for the LED strip.&lt;/li&gt;
  &lt;li&gt;Craft glue&lt;/li&gt;
  &lt;li&gt;Craft knife&lt;/li&gt;
  &lt;li&gt;Wire cutters&lt;/li&gt;
  &lt;li&gt;Wire strippers&lt;/li&gt;
  &lt;li&gt;Soldering iron and solder&lt;/li&gt;
  &lt;li&gt;Heat shrink&lt;/li&gt;
  &lt;li&gt;Heat gun&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;brief-construction-instructions&quot;&gt;Brief Construction Instructions&lt;/h1&gt;

&lt;p&gt;Here’s a rough description of how I built the project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Write a trivial Arduino sketch (program) that turns on the appropriate number
of LEDs to a low-brightness white color. I used brightness 30 (out of 255). You
may want to experiment. I based my program on Adafruit’s WS2812 test sample
sketch, which uses the Adafruit NeoPixel library. Program the Arduino with this
program. Below is the code I’m using right now. If/when I get around to adding
more features, I expect I’ll publish it on github.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;Adafruit_NeoPixel.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#define NUM_LEDS 34
#define DATA_PIN 13
#define BRIGHTNESS 32
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Adafruit_NeoPixel&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Adafruit_NeoPixel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NUM_LEDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DATA_PIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NEO_GRB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NEO_KHZ800&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;kt&quot;&gt;uint32_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BRIGHTNESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BRIGHTNESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BRIGHTNESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NUM_LEDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setPixelColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Cut LED strip to length, being careful to cut only at the marked divisions
between the “cells”.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Lay the LED strip onto a piece of cardboard and mark it to show the
length/width that needs to be cut out. Remove the LEDs and cut out the cardboard
backing strip.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The rear of the LED strip is usually mildly adhesive and covered by a
removable strip of paper. Remove this paper, cover the LED strip with some
extra glue, and apply the strip to the cardboard backing. I clamped mine in
place using binder clips until the glue dried.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Measure a length of cable to connect from the mounted LEDs to the controller
box. Solder one end of the wire onto the LED strip.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Cut holes into the project box for:
    &lt;ul&gt;
      &lt;li&gt;The power switch.&lt;/li&gt;
      &lt;li&gt;The power inlet cable.&lt;/li&gt;
      &lt;li&gt;The LED power/data cable.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Cut the device end off of the USB cable, thread it into the project box
through the power hole, and out through the switch hole.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Solder the two wires of the power cable to separate poles of one side of the
DPDT power switch.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Solder two short wires to the other side of the DPDT switch, and thread those
back into the project box.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Solder a female JST connector to:
    &lt;ul&gt;
      &lt;li&gt;The output side of the DPDT power switch. You may wish to wrap the switch
  pins in heat shrink.&lt;/li&gt;
      &lt;li&gt;A wire with a female 0.1” connector. You may wish to heat-shrink the
  connection.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Mount the switch into the project box, and thread the female JST cable out of
the other hole in the project box.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Connect the wires from the power switch to the Arduino header’s power input
pins.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Connect the control wire from the LED connector to one of the Arduino’s data
pins.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Tape the Arduino into the project box so that it won’t move around and short
on&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Solder a male JST connector to the end of the LED power/control wire.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Close up the project box, and install it its final location.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Connect the LED strip’s JST connector to the JST connector poking out from
the project box.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Plug in the power to the project box. Behold your new reading light!&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;changelog&quot;&gt;Changelog&lt;/h1&gt;

&lt;p&gt;2017/03/22: Embedded the Arduino code in the article.&lt;/p&gt;

&lt;p&gt;2017/03/21: Fixed various typos. Cropped and scaled images.&lt;/p&gt;
</description>
          <pubDate>2017-03-18T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2017/03/18/ws2812-reading-light.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2017/03/18/ws2812-reading-light.html</guid>
        </item>
      
    
      
        <item>
          <title>Welcome</title>
          <description>&lt;p&gt;For a while I’ve been meaning to create a place to write up various projects
I’ve worked on, or the occasional other topic. Well, here it is!&lt;/p&gt;

&lt;p&gt;Google+ and similar site work great for sharing posts, but I wanted something
with better formatting and image embedding opportunities to allow more detailed
write-ups.&lt;/p&gt;

&lt;p&gt;I initially considered using Github Pages, since it’s based around git and
Markdown, thus is really simple to set up and use. However, I soon decided I’d
rather host it myself, since I already have my own web server. Besides, the
engine behind Github pages is Jekyll, and I can quite easily run that myself
and get essentially the exact same feature set.&lt;/p&gt;
</description>
          <pubDate>2017-03-17T00:00:00-06:00</pubDate>
          <link>http://rabbithole.wwwdotorg.org//2017/03/17/welcome.html</link>
          <guid isPermaLink="true">http://rabbithole.wwwdotorg.org//2017/03/17/welcome.html</guid>
        </item>
      
    
  </channel>
</rss>
