<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SSH on Ash Tewari</title><link>https://www.tewari.info/tag/ssh/</link><description>Recent content in SSH on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sun, 28 Mar 2021 03:33:11 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/ssh/feed.xml" rel="self" type="application/rss+xml"/><item><title>AKS - Adding SSH Keys to VMSS Nodes</title><link>https://www.tewari.info/2021/03/27/aks-adding-ssh-keys-to-vmss-nodes/</link><pubDate>Sun, 28 Mar 2021 03:33:11 +0000</pubDate><guid>https://www.tewari.info/2021/03/27/aks-adding-ssh-keys-to-vmss-nodes/</guid><description>&lt;p&gt;You can connect to Azure Kubernetes Service (AKS) nodes using ssh. It is documented here: &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/aks/ssh" target="_blank" rel="noopener"&#10; &gt;Connect with SSH to Azure Kubernetes Service (AKS) cluster nodes for maintenance or troubleshooting&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;I needed to access nodes on the System node pool for collecting some logs recently, but the process documented above was not working for me. It turns out that there were two different issues, both related to adding your SSH keys to the nodes in a virtual machine scale set (VMSS).&lt;/p&gt;&#10;&lt;p&gt;This is the az cli command that adds the ssh keys to the VMSS:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;az vmss extension set \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --resource-group $CLUSTER_RESOURCE_GROUP \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --vmss-name $SCALE_SET_NAME \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --name VMAccessForLinux \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --publisher Microsoft.OSTCExtensions \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --version 1.4 \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --protected-settings &amp;#34;{\&amp;#34;username\&amp;#34;:\&amp;#34;azureuser\&amp;#34;, \&amp;#34;ssh_key\&amp;#34;:\&amp;#34;$(cat ~/.ssh/id_rsa.pub)\&amp;#34;}&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I was running this command from powershell on a windows host. So, the first modification I needed was to escape the double quotes by doubling them. You can also &lt;a class="link" href="http://www.rlmueller.net/PowerShellEscape.htm" target="_blank" rel="noopener"&#10; &gt;use back ticks&lt;/a&gt; instead of doubling the double quotes.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;az vmss extension set \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --resource-group $CLUSTER_RESOURCE_GROUP \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --vmss-name $SCALE_SET_NAME \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --name VMAccessForLinux \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --publisher Microsoft.OSTCExtensions \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --version 1.4 \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --protected-settings &amp;#34;{\&amp;#34;&amp;#34;username\&amp;#34;&amp;#34;:\&amp;#34;&amp;#34;azureuser\&amp;#34;&amp;#34;, \&amp;#34;&amp;#34;ssh_key\&amp;#34;&amp;#34;:\&amp;#34;&amp;#34;$(cat ~/.ssh/id_rsa.pub)\&amp;#34;&amp;#34;}&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The second issue was due to the fact that ssh-keygen adds a comment to the id_rsa.pub file. By default, it adds username@hostname as the comment at the end of the file . Normally, this comment wouldn&amp;rsquo;t cause any problems, but in this case it was causing an error - &amp;ldquo;Invalid escape sequence \uXXXX&amp;rdquo;.&lt;/p&gt;&#10;&lt;p&gt;The problem was that my domain user name starts with character &amp;lsquo;u&amp;rsquo; and &amp;ldquo;domain\userid1&amp;rdquo; was being interpreted as containing a unicode character &amp;ldquo;\useri&amp;rdquo; which is obviously not a valid unicode character. The workaround here is to either delete the comment from the id_rsa.pub file (it works just fine without it) or to override the default comment when generating the ssh key by specifying your own comment via -C command line option.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ssh-keygen -C mycomment&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, there is another way to execute &lt;a class="link" href="https://docs.microsoft.com/en-us/cli/azure/vmss/extension?view=azure-cli-latest#az_vmss_extension_set" target="_blank" rel="noopener"&#10; &gt;az vmss extension set&lt;/a&gt; command to get around both of these issues by creating a json file and passing that as the value of &amp;ndash;protected-settings argument. Here is how -&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Create a json file, protected_settings.json, with the following content:&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#9;&amp;#34;username&amp;#34; : &amp;#34;azureuser&amp;#34;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#9;&amp;#34;ssh_key&amp;#34; : &amp;#34;REPLACE_THIS_WITH_CONTENT_OF_ID_RSA_PUB_FILE&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#10;&lt;li&gt;Pass this file as the command line argument:&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;az vmss extension set \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --resource-group $CLUSTER_RESOURCE_GROUP \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --vmss-name $SCALE_SET_NAME \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --name VMAccessForLinux \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --publisher Microsoft.OSTCExtensions \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --version 1.4 \&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; --protected-settings protected_settings.json&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Works like a charm!&lt;/p&gt;&#10;</description></item></channel></rss>