<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>sshkey &amp;mdash; Thoughts from a serf</title>
    <link>https://blog.durehed.se/tag:sshkey</link>
    <description>Working in tech. Writing on different matters. Sometimes in Swedish other times in English.</description>
    <pubDate>Sat, 18 Apr 2026 01:44:47 +0000</pubDate>
    <item>
      <title>Setting passwords securely with SSH-Key on Windows Servers running on OpenStack</title>
      <link>https://blog.durehed.se/ssh-keys-in-openstack-and-windows-server</link>
      <description>&lt;![CDATA[Regrettably, I have to work with Windows Server every day. I won&#39;t go into why I think this is regrettable in this post. But, one, of many, thing that sucks when running Windows Server is that so much information on the amazing world wide web is geared towards running applications on some sort of Linux. In the &#34;put something on a server&#34; world, some kind of Linux is the norm.&#xA;&#xA;Anyway, I wanted to create a local Administrator account without having to push a password through CloudBase-Init in the userdata configuration.&#xA;As an example one can do something like this:&#xA;&#xA;users:&#xA;  name: coolboy82&#xA;    groups: Administrators&#xA;    passwd: very-cool-and-strong-password&#xA;    sshauthorized_keys:&#xA;      ssh-rsa AAAB...byV&#xA;However, even if the above do work you get a little bit of a security issue with this approach. Say that you forget to reset the password you give user You might use this as a default account that you always add when you create new instances in OpenStack. Well, then you have a security issue.&#xA;&#xA;Let CloudBase-Init generate user password &#xA;One solution for this is to let Cloudbase-Init to do the password generation for you. Then you retrieve it later through the magic of encryption. However, I ran into some issues. Whenever I tried to retrieve the password from the OpenStack CLI I got the following error:&#xA;&#xA;So, something was wrong. And as so many times before, the error were somewhere behind the keyboard.&#xA;&#xA;When you create an instance in OpenStack you tell it to use a ssh-key public key of your choice. The ssh-key public key can be used to encrypt the password that Cloud-Base Init generates so that ONLY the one who has access to the private key can decrypt it.&#xA;&#xA;It is quite easy, but I ran in to a gotcha. Turns out that it is very important to create the ssh-key in a specific format and type of key. Also, if you password protect your private key, you can&#39;t retrieve the password from the OpenStack Horizon UI.&#xA;&#xA;We need to use a ssh-key with type &#xA;So to generate a ssh-key of the correct type and format the following should suffice: &#xA;&#xA;So, then to retrieve the password generated for an instance use the OpenStack CLI with the following command:&#xA;&#xA;So, all is well. If you simply do things the right way things work better. One thing that I do feel is not so &#34;well&#34; is the documentation from OpenStack and some of the OpenStack providers. I did search a hell of a lot to find information about this issue and I could not find conclusive, to me at least, information about what OpenStack required in terms of ssh-keys and formats. One good reasource is from the Swedish OpenStack provider Safespring. They have a very good blog post about ssh-keys and OpenStack.&#xA;&#xA;Anyway, I put this out on the wide wide wide web to let any body else have the chance to find this quicker than I did.&#xA;&#xA;#openstack #sshkey #cloudbaseinit #cloudinit #tkey #tillitis&#xA;&#xA; &#xA;&#xA;Joakim Durehed&#xD;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Regrettably, I have to work with Windows Server every day. I won&#39;t go into why I think this is regrettable in this post. But, one, of many, thing that sucks when running Windows Server is that so much information on the amazing world wide web is geared towards running applications on some sort of Linux. In the “put something on a server” world, some kind of Linux is the norm.</p>

<p>Anyway, I wanted to create a local Administrator account without having to push a password through <a href="https://cloudbase.it/cloudbase-init/">CloudBase-Init</a> in the user_data configuration.
As an example one can do something like this:</p>

<pre><code class="language-yaml">users:
  - name: cool_boy_82
    groups: Administrators
    passwd: very-cool-and-strong-password
    ssh_authorized_keys:
      - ssh-rsa AAAB...byV
</code></pre>

<p>However, even if the above do work you get a little bit of a security issue with this approach. Say that you forget to reset the password you give user <code>cool_boy_82</code> and you have some kind of breach. It can be possible to either read the logs from CloudBase-Init in <code>C:\Program files\Cloudbase</code> or to fetch the logs from the metadata service. Because if you put the password in clear text, it will be available in the logs in clear text.
You might use this as a default account that you always add when you create new instances in OpenStack. Well, then you have a security issue.</p>

<h2 id="let-cloudbase-init-generate-user-password">Let CloudBase-Init generate user password</h2>

<p>One solution for this is to let Cloudbase-Init to do the password generation for you. Then you retrieve it later through the magic of encryption. However, I ran into some issues. Whenever I tried to retrieve the password from the OpenStack CLI I got the following error:</p>

<p><code>b&#39;unable to load Private Key [...] PEM routines [...]</code></p>

<p>So, something was wrong. And as so many times before, the error were somewhere behind the keyboard.</p>

<p>When you create an instance in OpenStack you tell it to use a ssh-key public key of your choice. The ssh-key public key can be used to encrypt the password that Cloud-Base Init generates so that ONLY the one who has access to the private key can decrypt it.</p>

<p>It is quite easy, but I ran in to a gotcha. Turns out that it is very important to create the ssh-key in a specific format and type of key. Also, if you password protect your private key, you can&#39;t retrieve the password from the OpenStack Horizon UI.</p>

<p>We need to use a ssh-key with type <code>rsa</code> and make sure that it is in the <code>pem</code> format. I use <code>ed25519</code> as my type of choice. Especially after I started using a <a href="https://tillitis.se/products/tkey/">TKey</a>  from Tillitis wich only generates <code>ed25519</code> keys.</p>

<p>So to generate a ssh-key of the correct type and format the following should suffice:</p>

<p><code>ssh-keygen -t rsa -m PEM -f  &#34;cool_boy_82&#34;</code></p>

<p>So, then to retrieve the password generated for an instance use the OpenStack CLI with the following command:</p>

<p><code>nova get-password {instanceID} {PathTo: private key file}</code></p>

<p>So, all is well. If you simply do things the right way things work better. One thing that I do feel is not so “well” is the documentation from OpenStack and some of the OpenStack providers. I did search a hell of a lot to find information about this issue and I could not find conclusive, to me at least, information about what OpenStack required in terms of ssh-keys and formats. One good reasource is from the Swedish OpenStack provider Safespring. They have a <a href="https://www.safespring.com/blogg/2022/2022-03-ssh-keys/">very good blog post about ssh-keys and OpenStack</a>.</p>

<p>Anyway, I put this out on the wide wide wide web to let any body else have the chance to find this quicker than I did.</p>

<p><a href="https://blog.durehed.se/tag:openstack" class="hashtag"><span>#</span><span class="p-category">openstack</span></a> <a href="https://blog.durehed.se/tag:sshkey" class="hashtag"><span>#</span><span class="p-category">sshkey</span></a> <a href="https://blog.durehed.se/tag:cloudbaseinit" class="hashtag"><span>#</span><span class="p-category">cloudbaseinit</span></a> <a href="https://blog.durehed.se/tag:cloudinit" class="hashtag"><span>#</span><span class="p-category">cloudinit</span></a> <a href="https://blog.durehed.se/tag:tkey" class="hashtag"><span>#</span><span class="p-category">tkey</span></a> <a href="https://blog.durehed.se/tag:tillitis" class="hashtag"><span>#</span><span class="p-category">tillitis</span></a></p>

<p>Joakim Durehed</p>
]]></content:encoded>
      <guid>https://blog.durehed.se/ssh-keys-in-openstack-and-windows-server</guid>
      <pubDate>Sun, 11 Aug 2024 09:07:23 +0000</pubDate>
    </item>
  </channel>
</rss>