HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //usr/share/doc/python27-paramiko-1.15.1/docs/api/hostkeys.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Host keys / known_hosts files &mdash; Paramiko  documentation</title>
    
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="Paramiko  documentation" href="../index.html" />
    <link rel="next" title="Key handling" href="keys.html" />
    <link rel="prev" title="SSH agents" href="agent.html" />
   
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="keys.html" title="Key handling"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="agent.html" title="SSH agents"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">Paramiko  documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-paramiko.hostkeys">
<span id="host-keys-known-hosts-files"></span><h1>Host keys / <tt class="docutils literal"><span class="pre">known_hosts</span></tt> files<a class="headerlink" href="#module-paramiko.hostkeys" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="paramiko.hostkeys.HostKeys">
<em class="property">class </em><tt class="descclassname">paramiko.hostkeys.</tt><tt class="descname">HostKeys</tt><big>(</big><em>filename=None</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys" title="Permalink to this definition">¶</a></dt>
<dd><p>Representation of an OpenSSH-style &#8220;known hosts&#8221; file.  Host keys can be
read from one or more files, and then individual hosts can be looked up to
verify server keys during SSH negotiation.</p>
<p>A <a class="reference internal" href="#paramiko.hostkeys.HostKeys" title="paramiko.hostkeys.HostKeys"><tt class="xref py py-obj docutils literal"><span class="pre">HostKeys</span></tt></a> object can be treated like a dict; any dict lookup is
equivalent to calling <a class="reference internal" href="#paramiko.hostkeys.HostKeys.lookup" title="paramiko.hostkeys.HostKeys.lookup"><tt class="xref py py-obj docutils literal"><span class="pre">lookup</span></tt></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.3.</span></p>
</div>
<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.__init__">
<tt class="descname">__init__</tt><big>(</big><em>filename=None</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new HostKeys object, optionally loading keys from an OpenSSH
style host-key file.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; filename to load host keys from, or <tt class="docutils literal"><span class="pre">None</span></tt></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.add">
<tt class="descname">add</tt><big>(</big><em>hostname</em>, <em>keytype</em>, <em>key</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a host key entry to the table.  Any existing entry for a
<tt class="docutils literal"><span class="pre">(hostname,</span> <span class="pre">keytype)</span></tt> pair will be replaced.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>hostname</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; the hostname (or IP) to add</li>
<li><strong>keytype</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; key type (<tt class="docutils literal"><span class="pre">&quot;ssh-rsa&quot;</span></tt> or <tt class="docutils literal"><span class="pre">&quot;ssh-dss&quot;</span></tt>)</li>
<li><strong>key</strong> (<em>.PKey</em>) &#8211; the key to add</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.load">
<tt class="descname">load</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.load" title="Permalink to this definition">¶</a></dt>
<dd><p>Read a file of known SSH host keys, in the format used by OpenSSH.
This type of file unfortunately doesn&#8217;t exist on Windows, but on
posix, it will usually be stored in
<tt class="docutils literal"><span class="pre">os.path.expanduser(&quot;~/.ssh/known_hosts&quot;)</span></tt>.</p>
<p>If this method is called multiple times, the host keys are merged,
not cleared.  So multiple calls to <a class="reference internal" href="#paramiko.hostkeys.HostKeys.load" title="paramiko.hostkeys.HostKeys.load"><tt class="xref py py-obj docutils literal"><span class="pre">load</span></tt></a> will just call <a class="reference internal" href="#paramiko.hostkeys.HostKeys.add" title="paramiko.hostkeys.HostKeys.add"><tt class="xref py py-obj docutils literal"><span class="pre">add</span></tt></a>,
replacing any existing entries and adding new ones.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; name of the file to read host keys from</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises IOError:</th><td class="field-body">if there was an error reading the file</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.save">
<tt class="descname">save</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.save" title="Permalink to this definition">¶</a></dt>
<dd><p>Save host keys into a file, in the format used by OpenSSH.  The order of
keys in the file will be preserved when possible (if these keys were
loaded from a file originally).  The single exception is that combined
lines will be split into individual key lines, which is arguably a bug.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; name of the file to write</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises IOError:</th><td class="field-body">if there was an error writing the file</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.6.1.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.lookup">
<tt class="descname">lookup</tt><big>(</big><em>hostname</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.lookup" title="Permalink to this definition">¶</a></dt>
<dd><p>Find a hostkey entry for a given hostname or IP.  If no entry is found,
<tt class="docutils literal"><span class="pre">None</span></tt> is returned.  Otherwise a dictionary of keytype to key is
returned.  The keytype will be either <tt class="docutils literal"><span class="pre">&quot;ssh-rsa&quot;</span></tt> or <tt class="docutils literal"><span class="pre">&quot;ssh-dss&quot;</span></tt>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>hostname</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; the hostname (or IP) to lookup</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">dict of <a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><tt class="xref py py-obj docutils literal"><span class="pre">str</span></tt></a> -&gt; <a class="reference internal" href="keys.html#paramiko.pkey.PKey" title="paramiko.pkey.PKey"><tt class="xref py py-obj docutils literal"><span class="pre">PKey</span></tt></a> keys associated with this host (or <tt class="docutils literal"><span class="pre">None</span></tt>)</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.check">
<tt class="descname">check</tt><big>(</big><em>hostname</em>, <em>key</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.check" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the given key is associated with the given hostname
in this dictionary.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>hostname</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; hostname (or IP) of the SSH server</li>
<li><strong>key</strong> (<em>.PKey</em>) &#8211; the key to check</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">True</span></tt> if the key is associated with the hostname; else <tt class="docutils literal"><span class="pre">False</span></tt></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeys.clear">
<tt class="descname">clear</tt><big>(</big><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all host keys from the dictionary.</p>
</dd></dl>

<dl class="staticmethod">
<dt id="paramiko.hostkeys.HostKeys.hash_host">
<em class="property">static </em><tt class="descname">hash_host</tt><big>(</big><em>hostname</em>, <em>salt=None</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeys.hash_host" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a &#8220;hashed&#8221; form of the hostname, as used by OpenSSH when storing
hashed hostnames in the known_hosts file.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>hostname</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; the hostname to hash</li>
<li><strong>salt</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; optional salt to use when hashing (must be 20 bytes long)</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the hashed hostname as a <a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><tt class="xref py py-obj docutils literal"><span class="pre">str</span></tt></a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="paramiko.hostkeys.HostKeyEntry">
<em class="property">class </em><tt class="descclassname">paramiko.hostkeys.</tt><tt class="descname">HostKeyEntry</tt><big>(</big><em>hostnames=None</em>, <em>key=None</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeyEntry" title="Permalink to this definition">¶</a></dt>
<dd><p>Representation of a line in an OpenSSH-style &#8220;known hosts&#8221; file.</p>
<dl class="classmethod">
<dt id="paramiko.hostkeys.HostKeyEntry.from_line">
<em class="property">classmethod </em><tt class="descname">from_line</tt><big>(</big><em>line</em>, <em>lineno=None</em><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeyEntry.from_line" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses the given line of text to find the names for the host,
the type of key, and the key data. The line is expected to be in the
format used by the OpenSSH known_hosts file.</p>
<p>Lines are expected to not have leading or trailing whitespace.
We don&#8217;t bother to check for comments or empty lines.  All of
that should be taken care of before sending the line to us.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>line</strong> (<a class="reference external" href="http://docs.python.org/2.6/library/functions.html#str" title="(in Python v2.6)"><em>str</em></a>) &#8211; a line from an OpenSSH known_hosts file</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="paramiko.hostkeys.HostKeyEntry.to_line">
<tt class="descname">to_line</tt><big>(</big><big>)</big><a class="headerlink" href="#paramiko.hostkeys.HostKeyEntry.to_line" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a string in OpenSSH known_hosts file format, or None if
the object is not in a valid state.  A trailing newline is
included.</p>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">Paramiko</a></h1>



<p class="blurb">A Python implementation of SSHv2.</p>



<p>
<iframe src="http://ghbtns.com/github-btn.html?user=paramiko&repo=paramiko&type=watch&count=true&size=large"
  allowtransparency="true" frameborder="0" scrolling="0" width="200px" height="35px"></iframe>
</p>




    

<p>
<a href="https://travis-ci.org/paramiko/paramiko">
    <img
        alt="https://secure.travis-ci.org/paramiko/paramiko.png?branch=master"
        src="https://secure.travis-ci.org/paramiko/paramiko.png?branch=master"
    >
</a>
</p>
<h3>Navigation</h3>
<ul>
<li class="toctree-l1"><a class="reference internal" href="channel.html">Channel</a></li>
<li class="toctree-l1"><a class="reference internal" href="client.html">Client</a></li>
<li class="toctree-l1"><a class="reference internal" href="message.html">Message</a></li>
<li class="toctree-l1"><a class="reference internal" href="packet.html">Packetizer</a></li>
<li class="toctree-l1"><a class="reference internal" href="transport.html">Transport</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="agent.html">SSH agents</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Host keys / <tt class="docutils literal"><span class="pre">known_hosts</span></tt> files</a></li>
<li class="toctree-l1"><a class="reference internal" href="keys.html">Key handling</a></li>
<li class="toctree-l1"><a class="reference internal" href="ssh_gss.html">GSS-API authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="kex_gss.html">GSS-API key exchange</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="config.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="proxy.html"><tt class="docutils literal"><span class="pre">ProxyCommand</span></tt> support</a></li>
<li class="toctree-l1"><a class="reference internal" href="server.html">Server implementation</a></li>
<li class="toctree-l1"><a class="reference internal" href="sftp.html">SFTP</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="buffered_pipe.html">Buffered pipes</a></li>
<li class="toctree-l1"><a class="reference internal" href="file.html">Buffered files</a></li>
<li class="toctree-l1"><a class="reference internal" href="pipe.html">Cross-platform pipe implementations</a></li>
<li class="toctree-l1"><a class="reference internal" href="ssh_exception.html">Exceptions</a></li>
</ul>


<hr />
<ul>
    
    <li class="toctree-l1"><a href="http://www.paramiko.org">Main website</a></li>
    
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
<h3>Donate</h3>
<p>
Consider supporting the authors on <a href="https://www.gratipay.com/">Gratipay</a>:
<script data-gratipay-username="bitprophet"
        data-gratipay-widget="button"
        src="//gttp.co/v1.js"></script>
</p>

        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2014 Jeff Forcier.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.2.2</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.6.1</a>
      
      |
      <a href="../_sources/api/hostkeys.txt"
          rel="nofollow">Page source</a></li>
    </div>

    

    
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-18486793-2']);
      _gaq.push(['_setDomainName', 'none']);
      _gaq.push(['_setAllowLinker', true]);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
    
  </body>
</html>