<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tobias Grasse</title>
    <description>The latest articles on DEV Community by Tobias Grasse (@tobias_grasse).</description>
    <link>https://dev.to/tobias_grasse</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F11081%2F14bc1147-d53e-4c70-be35-ac9cc3d96525.jpeg</url>
      <title>DEV Community: Tobias Grasse</title>
      <link>https://dev.to/tobias_grasse</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tobias_grasse"/>
    <language>en</language>
    <item>
      <title>Quickly remove an entry from known_hosts</title>
      <dc:creator>Tobias Grasse</dc:creator>
      <pubDate>Fri, 08 Jan 2021 11:38:11 +0000</pubDate>
      <link>https://dev.to/tobias_grasse/quickly-remove-an-entry-from-knownhosts-1mfd</link>
      <guid>https://dev.to/tobias_grasse/quickly-remove-an-entry-from-knownhosts-1mfd</guid>
      <description>&lt;p&gt;Do you SSH to servers a lot? Then this will sooner or later pop up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
&amp;lt;host key&amp;gt;.
Please contact your system administrator.
Add correct host key in /path/to/.ssh/known_hosts to get rid of this message.
Offending key in /path/to/.ssh/known_hosts:&amp;lt;line&amp;gt;
RSA host key for [ip-or-host]:&amp;lt;port&amp;gt; has changed and you have requested strict checking.
Host key verification failed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the user-friendlier error messages I've encountered: What went wrong, possible causes, what to do, pointer to the &lt;code&gt;known_hosts&lt;/code&gt; file/line that caused this.&lt;/p&gt;

&lt;p&gt;When you connect to an existing, well-known server that wasn't modified, you should check with your friendly admin or hosting provider – in case someone has actually meddled with your server.&lt;/p&gt;

&lt;p&gt;However, my work on IoT devices involves a lot of SSH'ing to local devices, and frequent teardown/re-flash means they get assigned the same IP address/host name as a previous device – but with a different host key. So each time, OpenSSH will issue its dutiful warning above. I don't want to disable strict checking completely or on a per-host basis. Removing the offending line by hand each time gets tedious, but luckily OpenSSL's &lt;code&gt;ssh-keygen&lt;/code&gt; can take care of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-R&lt;/span&gt; &amp;lt;ip-or-hostname&amp;gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"/path/to/.ssh/known_hosts"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still to much to type on a regular basis. My shell of choice is &lt;a href="https://fishshell.com"&gt;fish&lt;/a&gt;, so I wrapped this in a function &lt;code&gt;rmkh&lt;/code&gt; (“remove known host”):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;rmkh &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"removes a given host from ~/.ssh/known_hosts"&lt;/span&gt;
  ssh-keygen &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$argv&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"/path/to/.ssh/known_hosts"&lt;/span&gt;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the next time I get a host verification message, I can just run &lt;code&gt;rmkh &amp;lt;offending-host-or-ip&amp;gt;&lt;/code&gt; and get on with it. Also works with multiple hosts.&lt;/p&gt;

&lt;p&gt;Note: At least inside a fish function, this needs to have the full path to your &lt;code&gt;known_hosts&lt;/code&gt; file &lt;em&gt;as a string&lt;/em&gt;, so don't use a tilde and quote everything to be safe.&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>shell</category>
      <category>fish</category>
    </item>
  </channel>
</rss>
