<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Openssh on n3s0 || notes</title>
    <link>https://notes.n3s0.tech/tags/openssh/</link>
    <description>Recent content in Openssh on n3s0 || notes</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Wed, 06 Jul 2022 14:37:20 -0500</lastBuildDate><atom:link href="https://notes.n3s0.tech/tags/openssh/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Linux &amp; BSD: Configuring &amp; Using OpenSSH Client on Cisco Devices Using Legacy Key Algorithms</title>
      <link>https://notes.n3s0.tech/posts/20220706143720/</link>
      <pubDate>Wed, 06 Jul 2022 14:37:20 -0500</pubDate>
      
      <guid>https://notes.n3s0.tech/posts/20220706143720/</guid>
      <description>Notes for troubleshooting legacy key algorithms on Linux.</description>
      <content:encoded><![CDATA[<h2 id="summary">Summary</h2>
<p>This is an old thing I came across. But, useful to know all the same.
This post discusses some issues with devices such as Cisco routers,
switches, etc. where the key exchange algorithms and host key algorithm
types are weaker and/or riskier key algorithms. These algorithms are
considered legacy options that may need to be specified when connecting
to the host.</p>
<h2 id="making-it-work-as-unintended">Making It Work as Unintended</h2>
<p>If OpenSSH encounters a legacy Host Key or Key Exchange algorithm on the
server it&rsquo;s connecting to. The client will refuse the connection not
allowing you to connect to it.</p>
<p>The Cisco switch I was attempting to login to had only the following key
exchange algorithms available. So the OpenSSH client wouldn&rsquo;t allow me
to connect to the device.</p>
<ul>
<li>diffie-hellman-group-exchange-sha1</li>
<li>diffie-hellman-group14-sha1</li>
</ul>
<p>Which is good. We shouldn&rsquo;t be using legacy SSH key exchange algorithms
for ssh sessions unless we have to. In this case I kind of have to. This
is a Cisco switch I&rsquo;m using in my lab and don&rsquo;t really intend to buy one
brand new from Cisco.</p>
<p>Below is the error output of the switches key exchange offering. Stating
that there wasn&rsquo;t one available.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">Unable to negotiate with 192.168.0.3 port 22: no matching key exchange method found. 
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
</span></span></code></pre></div><p>Connected to the switch using the -o switch and appended
diffie-hellman-group1-sha1 as a key exchange algorithm and I was able to
login.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">ssh -oKexAlgorithms<span class="o">=</span>+diffie-hellman-group1-sha1 user@slab-csw-01.lab.home.n3s0
</span></span></code></pre></div><p>This can also be added to the users ~/.ssh/config file with the host
specified so it isolates these options for this host. The KexAlgorithms
appended with the + key exchange algorithm. It will make the key
algorithm available for use by the OpenSSH client for the host that&rsquo;s
listed.</p>
<pre tabindex="0"><code class="language-ssh" data-lang="ssh">Host slab-csw-01.lab.home.n3s0
	KexAlgorithms +diffie-hellman-group1-sha1
</code></pre><p>I have found that there is a side effect to doing so though, based on
the output provided below. Looks like the ssh-rsa host key algorithm
isn&rsquo;t found/available either. This is an OpenBSD machine I&rsquo;m connecting
to the switch from and I believe ssh-rsa has been made a legacy option.
This probably isn&rsquo;t necessary on Linux devices though. Haven&rsquo;t quite
tested that yet.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">Unable to negotiate with 192.168.0.3 port 22: no matching host key <span class="nb">type</span> found. 
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Their offer: ssh-rsa
</span></span></code></pre></div><p>Using the HostKeyAlgorithms option and appending the ssh-rsa option to
the list of host key algorithms available makes it so I can connect to
the switch.</p>
<pre tabindex="0"><code class="language-ssh" data-lang="ssh">ssh -oHostKeyAlgorithms=+ssh-rsa user@slab-csw-01.lab.home.n3s0
</code></pre><p>This can also be added to the ~/.ssh/config file also. I do this by
adding another line. Now I don&rsquo;t have to add that as another option.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-vim" data-lang="vim"><span class="line"><span class="cl"><span class="nx">Host</span> <span class="nx">slab</span><span class="p">-</span><span class="nx">csw</span><span class="m">-01</span>.<span class="nx">lab</span>.<span class="nx">home</span>.<span class="nx">n3s0</span>
</span></span><span class="line"><span class="cl">	<span class="nx">KexAlgorithms</span> <span class="p">+</span><span class="nx">diffie</span><span class="p">-</span><span class="nx">hellman</span><span class="p">-</span><span class="nx">group1</span><span class="p">-</span><span class="nx">sha1</span>
</span></span><span class="line"><span class="cl">	<span class="nx">HostKeyAlgorithms</span> <span class="p">+</span><span class="nx">ssh</span><span class="p">-</span><span class="nx">rsa</span>
</span></span></code></pre></div><p>There are other key errors that can pop up. I&rsquo;m just providing this for
notation purposes. One bit of advice I can give is to read the errors
you&rsquo;re presented. SSH will provide the information related to the
key offering of the remote host.</p>
<p>Also pay attention to the key exchange and the key type that&rsquo;s offered
so that can be applied to the connection.</p>
<h2 id="further-troubleshooting">Further Troubleshooting</h2>
<p>Another method for troubleshooting missing key exchange algorithms and
host key algorithms is by querying which algorithms are available to the
OpenSSH client.</p>
<p>This one will check the key exchange algorithms available within the
OpenSSH client.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">ssh -Q kex
</span></span></code></pre></div><p>This one will check for key types available in the OpenSSH client.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">ssh -Q key
</span></span></code></pre></div><p>There is another option. One that isn&rsquo;t necessarily documented in the
ssh(1) man page on this Linux box; but is usable in it, I&rsquo;m writing
this post on. But, it&rsquo;s documented in the actual OpenSSH(1) man page
hosted on openssh.org. Sounds like I&rsquo;ll need to search for it more.</p>
<p>I&rsquo;ll provide a link in the references. The -G option can be used to
print the configuration after evaluating Host and Match blocks. Pretty
useful should there be a need to print what algorithms and key types are
being used for a specific host at the time of the connection.</p>
<p>The command for this can be found below. Just need to replace the host
with the device I need to connect to.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">ssh -G user@slab-csw-01.lab.home.n3s0
</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2>
<p>Here went over some notes related to OpenSSH troubleshooting of devices
that only offer legacy key exchange algorithms and key types. Hopefully
this is useful in the future. Should anyone need resources. They&rsquo;re in
the next section.</p>
<h2 id="references">References</h2>
<ul>
<li><a href="https://man.openbsd.org/ssh">OpenBSD SSH Man Page</a></li>
<li><a href="#">man ssh</a></li>
<li><a href="https://www.openssh.com/legacy.html">OpenSSH Legacy Options</a></li>
</ul>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
