<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>svnscha - devops</title>
    <subtitle>automating annoying tasks, sharing tips, and embracing less frustration</subtitle>
    <link rel="self" type="application/atom+xml" href="https://svnscha.de/tags/devops/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://svnscha.de"/>
    <generator uri="https://astro.build/">Astro</generator>
    <updated>2025-10-10T00:00:00+00:00</updated>
    <id>https://svnscha.de/tags/devops/atom.xml</id>
    <entry xml:lang="en">
        <title>How to: Use Docker Remote Contexts with SSH</title>
        <published>2025-10-10T00:00:00+00:00</published>
        <updated>2025-10-10T00:00:00+00:00</updated>
        <author>
          <name>Sven Scharmentke</name>
        </author>
        <link rel="alternate" type="text/html" href="https://svnscha.de/posts/docker-remote-context/"/>
        <id>https://svnscha.de/posts/docker-remote-context/</id>
        <summary type="html">A simple and secure guide to configuring SSH-based Docker remote contexts for offloading resource-intensive Docker operations to a remote host while keeping your local environment lightweight.</summary>
        <content type="html" xml:base="https://svnscha.de/posts/docker-remote-context/">&lt;h2 id=&quot;the-problem-when-your-laptop-becomes-a-jet-engine&quot;&gt;The Problem: When Your Laptop Becomes a Jet Engine&lt;/h2&gt;
&lt;p&gt;Working on resource-intensive Docker projects often turns laptops into jet engines. The fans spin up, the CPU overheats, and performance degrades significantly. This is especially problematic when working with limited resources - lightweight laptops, VDI sessions, or simply wanting to preserve your hardware.&lt;/p&gt;
&lt;p&gt;An SSH-based Docker context keeps the development tools on your local machine while running Docker workloads on a more capable remote host. Your laptop stays responsive and the remote system handles the heavier work.&lt;/p&gt;
&lt;h2 id=&quot;step-1-prerequisites&quot;&gt;Step 1: Prerequisites&lt;/h2&gt;
&lt;p&gt;Before we start, ensure you have:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;SSH access configured&lt;/strong&gt; to your remote Docker host with a proper SSH config entry like:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# ~/.ssh/config&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Host docker-remote&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  HostName 10.10.10.10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  IdentityFile ~/.ssh/id_rsa&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  User ubuntu&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;&lt;strong&gt;Your user is in the docker group&lt;/strong&gt; on the remote host:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; usermod&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -aG&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; docker&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $USER&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's all the setup needed! Now let's create the Docker context.&lt;/p&gt;
&lt;h2 id=&quot;step-2-create-the-ssh-based-docker-context&quot;&gt;Step 2: Create the SSH-Based Docker Context&lt;/h2&gt;
&lt;p&gt;Creating the Docker context is incredibly simple when you have SSH properly configured.&lt;/p&gt;
&lt;h3 id=&quot;create-your-ssh-based-remote-context&quot;&gt;Create Your SSH-Based Remote Context&lt;/h3&gt;
&lt;p&gt;Create a new context using your SSH config host:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; create&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; docker-remote&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; --docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; host=ssh://docker-remote&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's it! Docker will use your existing SSH configuration, including the hostname, user, and identity file you've already set up.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The beauty of this approach:&lt;/strong&gt; No daemon.json changes, no TCP configuration, no port forwarding, no firewall rules, no TLS certificate generation - just leverage your existing SSH security infrastructure. Simple and elegant!&lt;/p&gt;
&lt;h3 id=&quot;check-your-current-contexts&quot;&gt;Check Your Current Contexts&lt;/h3&gt;
&lt;p&gt;First, let's see what contexts you currently have:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You'll probably see something like:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;NAME              DESCRIPTION                               DOCKER ENDPOINT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;default *         Current DOCKER_HOST based configuration   npipe:////./pipe/docker_engine&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;desktop-linux     Docker Desktop                            npipe:////./pipe/dockerDesktopLinuxEngine&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;desktop-windows   Docker Desktop                            npipe:////./pipe/dockerDesktopWindowsEngine&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;docker-remote                                               ssh://docker-remote&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;test-the-connection&quot;&gt;Test the Connection&lt;/h3&gt;
&lt;p&gt;Let's verify everything works:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; --context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; docker-remote&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; container&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you see your remote containers listed (or an empty list if none are running), congratulations! You're successfully connected to your remote Docker host via SSH.&lt;/p&gt;
&lt;h2 id=&quot;step-3-make-it-your-default-optional&quot;&gt;Step 3: Make It Your Default (Optional)&lt;/h2&gt;
&lt;p&gt;If you want to use the remote context by default, you can switch to it:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; docker-remote&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now all your &lt;code&gt;docker&lt;/code&gt; commands will automatically use the remote host:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; container&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# This now runs on your remote host!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;environment-variable-override&quot;&gt;Environment Variable Override&lt;/h3&gt;
&lt;p&gt;For more granular control, you can also use the &lt;code&gt;DOCKER_CONTEXT&lt;/code&gt; environment variable:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Windows PowerShell&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$env&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;:DOCKER_CONTEXT = &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;docker-remote&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Linux/macOS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; DOCKER_CONTEXT&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;docker-remote&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This approach is particularly useful in CI/CD scenarios or when you want different shells to use different contexts.&lt;/p&gt;
&lt;h2 id=&quot;why-ssh-is-better&quot;&gt;Why SSH is Better&lt;/h2&gt;
&lt;p&gt;Using SSH for Docker remote contexts offers several advantages over TCP:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: All communication is encrypted by default&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication&lt;/strong&gt;: Leverages existing SSH keys and authentication methods&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No daemon configuration&lt;/strong&gt;: No need to modify Docker daemon settings on the remote host&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Firewall friendly&lt;/strong&gt;: Uses standard SSH port (22)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Audit trail&lt;/strong&gt;: SSH logging provides better security monitoring&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;switching-between-contexts&quot;&gt;Switching Between Contexts&lt;/h2&gt;
&lt;p&gt;Need to switch back to local Docker for something? Easy:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# List available contexts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Switch to local Docker&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; default&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Or use a specific context for one command&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; --context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; container&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;bonus-powershell-function-for-quick-context-switching&quot;&gt;Bonus: PowerShell Function for Quick Context Switching&lt;/h2&gt;
&lt;p&gt;Here's a handy PowerShell function to make switching contexts even easier. Add this to your PowerShell profile for instant remote Docker activation:&lt;/p&gt;
&lt;h3 id=&quot;edit-your-powershell-profile&quot;&gt;Edit Your PowerShell Profile&lt;/h3&gt;
&lt;p&gt;First, open your PowerShell profile for editing:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;notepad &lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$PROFILE&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the file doesn't exist yet, PowerShell will ask if you want to create it - say yes.&lt;/p&gt;
&lt;h3 id=&quot;add-the-function&quot;&gt;Add the Function&lt;/h3&gt;
&lt;p&gt;Add this function to your profile:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt; docker-remote-activate&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;    $env:DOCKER_CONTEXT&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;docker-remote&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;    Write-Host&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;Docker context switched to remote host&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &lt;code&gt;&quot;docker-remote&quot;&lt;/code&gt; with whatever you named your remote context.&lt;/p&gt;
&lt;h3 id=&quot;save-and-reload&quot;&gt;Save and Reload&lt;/h3&gt;
&lt;p&gt;Save the file and reload your PowerShell profile:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$PROFILE&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;usage&quot;&gt;Usage&lt;/h3&gt;
&lt;p&gt;Now you can instantly activate remote Docker in any PowerShell session:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Activate remote Docker for this session only&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker-remote-activate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Now all Docker commands run remotely&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker ps&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker images&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker build .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The beauty of this approach is that it only affects the current PowerShell session - open a new terminal window and you're back to local Docker by default!&lt;/p&gt;
&lt;h3 id=&quot;global-vs-terminal-specific-context-switching&quot;&gt;Global vs Terminal-Specific Context Switching&lt;/h3&gt;
&lt;p&gt;You have two ways to switch between local and remote Docker contexts:&lt;/p&gt;
&lt;h4 id=&quot;global-context-switching&quot;&gt;Global Context Switching&lt;/h4&gt;
&lt;p&gt;Affects all terminals system-wide:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Switch globally to remote&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; docker-remote&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Switch back to local&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; default&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;terminal-specific-context&quot;&gt;Terminal-Specific Context&lt;/h4&gt;
&lt;p&gt;Affects only the current terminal session:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Terminal 1: Remote context&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker-remote-activate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker ps  &lt;/span&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# runs remotely&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Terminal 2: Still local context  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;docker ps  &lt;/span&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# runs locally&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Whether you prefer global context switching or terminal-specific control, Docker remote contexts give you the flexibility to work exactly how you want.&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;Using SSH-based Docker remote contexts provides a secure, simple solution for offloading resource-intensive Docker operations to remote hosts. With just a single command and proper SSH configuration, you can transform your development workflow without compromising security.&lt;/p&gt;
&lt;p&gt;The SSH approach eliminates the complexity of daemon configuration while providing enterprise-grade security through encrypted communication and existing authentication infrastructure.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Benefits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Secure by default (encrypted communication)&lt;/li&gt;
&lt;li&gt;No daemon configuration required&lt;/li&gt;
&lt;li&gt;Uses standard SSH authentication&lt;/li&gt;
&lt;li&gt;Works with existing SSH infrastructure&lt;/li&gt;
&lt;li&gt;Simple one-command setup&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.docker.com/engine/manage-resources/contexts/&quot;&gt;Docker Context Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.docker.com/engine/context/remote/&quot;&gt;Docker SSH Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.ssh.com/academy/ssh/public-key-authentication&quot;&gt;SSH Key Authentication&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Simplify Elasticsearch and Kibana Installation</title>
        <published>2024-04-24T00:00:00+00:00</published>
        <updated>2024-04-24T00:00:00+00:00</updated>
        <author>
          <name>Sven Scharmentke</name>
        </author>
        <link rel="alternate" type="text/html" href="https://svnscha.de/posts/simplify-elasticsearch-kibana/"/>
        <id>https://svnscha.de/posts/simplify-elasticsearch-kibana/</id>
        <summary type="html">Let me walk you through how I created a bash script that sets up Elasticsearch and Kibana on a single-node cluster with minimal fuss.</summary>
        <content type="html" xml:base="https://svnscha.de/posts/simplify-elasticsearch-kibana/">&lt;h2 id=&quot;why-you-ask&quot;&gt;Why, You Ask?&lt;/h2&gt;
&lt;p&gt;Setting up Elasticsearch and Kibana involves the same steps each time: update the system, configure repositories, install packages, and apply the initial configuration. I wrote a script to automate that work and make the setup reusable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It's time-consuming and frustrating. I'm tired of it.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;automating-the-setup&quot;&gt;Automating the Setup&lt;/h2&gt;
&lt;p&gt;This Bash script installs Elasticsearch and Kibana as a single-node cluster. I use it when I need a small, repeatable setup without adding another configuration tool.&lt;/p&gt;
&lt;h2 id=&quot;why-choose-a-bash-script&quot;&gt;Why Choose a Bash Script?&lt;/h2&gt;
&lt;p&gt;I chose Bash instead of Ansible because the script also works well with cloud-init and inside Docker environments. It has no extra tooling requirements and is easy to copy to a new machine.&lt;/p&gt;
&lt;h2 id=&quot;building-the-script-a-step-by-step-guide&quot;&gt;Building the Script: A Step-by-Step Guide&lt;/h2&gt;
&lt;p&gt;Let's walk through the crafting of the script that automates setting up Elasticsearch and Kibana. Here's how I pieced it together, one step at a time:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Checking for Superuser Privileges
The script needs administrative access, so it starts by checking for root privileges.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#C586C0&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; [ &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -u&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;)&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; != &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;0&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; ]; &lt;/span&gt;&lt;span style=&quot;color:#C586C0&quot;&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;   echo&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;This script must be run as root&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; 1&amp;gt;&amp;amp;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;   exit&lt;/span&gt;&lt;span style=&quot;color:#B5CEA8&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#C586C0&quot;&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Updating the System and Installing Essential Packages
Updating the system first helps avoid installation problems caused by outdated packages.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;apt&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; update&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;apt&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -y&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; apt-transport-https&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; gnupg&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; curl&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; jq&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;
&lt;p&gt;Adding the Elasticsearch Repository
Getting this right is like picking the perfect ingredients for a master chef recipe - it ensures the rest of the meal turns out just right.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Installing Elasticsearch and Kibana
Next, the script installs Elasticsearch and Kibana.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Configuring and Starting Services
The plot thickens! Setting up the services and getting them running is like reaching the climax of our story - where all elements come together to unveil the full potential of our setup.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Rather than churn out another cookie-cutter guide on setting up Elasticsearch and Kibana, you can view the complete script &lt;a href=&quot;https://gist.github.com/svnscha/676291c9e1cdbfa261202b3897afba37&quot;&gt;here&lt;/a&gt;. However, I do want to emphasize the initial configuration process involving enrollment tokens and security settings. I've automated these aspects because, let's face it, I've read too many guides that suggest just turning off security for the sake of simplicity. That's not my style - I'd rather keep things secure automatically. It's not rocket science, but it sure is critical. Why simplify by compromising security when you can automate it effectively, right?&lt;/p&gt;
&lt;p&gt;This approach ensures you get the functionality you need without the hassle of manual setup or the risks of disabled security.&lt;/p&gt;
&lt;h2 id=&quot;perfecting-the-automation-securing-and-finalizing-the-setup&quot;&gt;Perfecting the Automation: Securing and Finalizing the Setup&lt;/h2&gt;
&lt;p&gt;The final part configures security and leaves both services ready to use.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Broadcasting the Good News
First things first, let's make sure any user logging into the system knows what's been accomplished:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;=== init-vm.sh: Initial ===&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; &amp;gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;/etc/motd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;[&amp;gt; Elasticsearch 'elastic' password: &lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$ELASTIC_PASSWORD&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; &amp;gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;/etc/motd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;[&amp;gt; Test instance with 'curl -k -X GET https://elastic:&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$ELASTIC_PASSWORD&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;@localhost:9200'&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; &amp;gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;/etc/motd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;=== init-vm.sh: Get started ===&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; &amp;gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;/etc/motd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;[&amp;gt; Reset 'elastic' password with '/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.&quot;&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; &amp;gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;/etc/motd&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, we're updating the message of the day (MOTD) file to ensure anyone who logs in is immediately informed about how to interact with Elasticsearch and what steps to take next. It's like leaving a note on the fridge - impossible to ignore and incredibly helpful.&lt;/p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Decoding the Secrets
Automation isn't just about doing things without human intervention; it's also about doing them securely and wisely:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A9955&quot;&gt;# Because who likes doing setup manually, right?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;decoded_token&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $KIBANA_ENROLLMENT_TOKEN&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;base64&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; --decode&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $decoded_token&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;jq&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '.adr[0]'&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;fingerprint&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $decoded_token&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;jq&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '.fgr'&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;api_key&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $decoded_token&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;jq&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '.key'&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Decoding the enrollment token reveals the essential elements needed to securely configure Kibana: the address, fingerprint, and API key.&lt;/p&gt;
&lt;p&gt;Harnessing Version and Build Information
Knowing exactly which version and build of Kibana you're working with is required for the API, so let's get that:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;ver&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;jq&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '.version'&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; /usr/share/kibana/package.json&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;build&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;jq&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '.build.number'&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; /usr/share/kibana/package.json&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;Re-encoding and Verification
Secrecy is paramount, and so is verification. Here's how we handle both:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;encoded_api_key&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $api_key&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;base64&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;output&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; /usr/share/kibana/bin/kibana-verification-code&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;verification_code&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;=$(&lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt; $output&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;awk&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -F&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '{print $2}'&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;sed&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; 's/ //g'&lt;/span&gt;&lt;span style=&quot;color:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The API key needs to be re-encoded to maintain security, and we also extract a verification code necessary for the next step - enrolling Kibana.&lt;/p&gt;
&lt;h2 id=&quot;the-final-act-enrolling-kibana&quot;&gt;The Final Act: Enrolling Kibana&lt;/h2&gt;
&lt;p&gt;And now, the final piece of our automation puzzle:&lt;/p&gt;
&lt;pre class=&quot;astro-code dark-plus&quot; style=&quot;background-color:#1E1E1E;color:#D4D4D4; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCDCAA&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -k&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -v&lt;/span&gt;&lt;span style=&quot;color:#569CD6&quot;&gt; -X&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; POST&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;http://localhost:5601/internal/interactive_setup/enroll&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;Accept: */*&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;Content-Type: application/json&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;Host: localhost:5601&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;Origin: http://localhost:5601&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;Referer: http://localhost:5601/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;kbn-build-number: &lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$build&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;kbn-version: &lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$ver&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;x-elastic-internal-origin: Kibana&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -H&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; &quot;x-kbn-context: %7B%22type%22%3A%22application%22%2C%22name%22%3A%22interactiveSetup%22%2C%22url%22%3A%22%2F%22%7D&quot;&lt;/span&gt;&lt;span style=&quot;color:#D7BA7D&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#569CD6&quot;&gt;     -d&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt; '{&quot;hosts&quot;:[&quot;https://'&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$address&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;'&quot;],&quot;apiKey&quot;:&quot;'&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$encoded_api_key&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;'&quot;,&quot;caFingerprint&quot;:&quot;'&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$fingerprint&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;'&quot;,&quot;code&quot;:&quot;'&lt;/span&gt;&lt;span style=&quot;color:#9CDCFE&quot;&gt;$verification_code&lt;/span&gt;&lt;span style=&quot;color:#CE9178&quot;&gt;'&quot;}'&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This curl command not only sends all the needed parameters to Kibana for configuration but also uses the verification code to ensure that the setup is both authorized and secure. It's akin to dotting the i's and crossing the t's in our setup script.&lt;/p&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;The script turns a fresh system into a secured, working Elasticsearch and Kibana installation. Feel free to adapt it to your own environment.&lt;/p&gt;
&lt;p&gt;Check out the complete script here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://gist.github.com/svnscha/676291c9e1cdbfa261202b3897afba37&quot;&gt;init-elastic-search-kibana-vm.sh&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Happy automating, and here's to many insightful data explorations!&lt;/p&gt;
&lt;p&gt;P.S.: This script is tailored for automating development environments. Remember, a single-node cluster isn’t suited for production use, and storing passwords in the message of the day (MOTD) file? That’s a no-go for serious deployments. 😏&lt;/p&gt;
</content>
    </entry>
</feed>
