Package paramiko :: Class HostKeys
[show private | hide private]
[frames | no frames]

Type HostKeys

object --+
         |
        HostKeys


Representation of an openssh-style "known hosts" 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.

A HostKeys object can be treated like a dict; any dict lookup is equivalent to calling lookup.

Since: 1.5.3

Method Summary
  __init__(self, filename)
Create a new HostKeys object, optionally loading keys from an openssh style host-key file.
  __getitem__(self, key)
  __len__(self)
  add(self, hostname, keytype, key)
Add a host key entry to the table.
bool check(self, hostname, key)
Return True if the given key is associated with the given hostname in this dictionary.
  clear(self)
Remove all host keys from the dictionary.
str hash_host(hostname, salt)
Return a "hashed" form of the hostname, as used by openssh when storing hashed hostnames in the known_hosts file. (Static method)
  load(self, filename)
Read a file of known SSH host keys, in the format used by openssh.
dict(str, PKey) lookup(self, hostname)
Find a hostkey entry for a given hostname or IP.
  values(self)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Instance Method Details

__init__(self, filename=None)
(Constructor)

Create a new HostKeys object, optionally loading keys from an openssh style host-key file.
Parameters:
filename - filename to load host keys from, or None
           (type=str)
Overrides:
__builtin__.object.__init__

add(self, hostname, keytype, key)

Add a host key entry to the table. Any existing entry for a (hostname, keytype) pair will be replaced.
Parameters:
hostname -
           (type=str)
keytype - key type ("ssh-rsa" or "ssh-dss")
           (type=str)
key - the key to add
           (type=PKey)

check(self, hostname, key)

Return True if the given key is associated with the given hostname in this dictionary.
Parameters:
hostname - hostname (or IP) of the SSH server
           (type=str)
key - the key to check
           (type=PKey)
Returns:
True if the key is associated with the hostname; False if not
           (type=bool)

clear(self)

Remove all host keys from the dictionary.

load(self, filename)

Read a file of known SSH host keys, in the format used by openssh. This type of file unfortunately doesn't exist on Windows, but on posix, it will usually be stored in os.path.expanduser("~/.ssh/known_hosts").
Parameters:
filename - name of the file to read host keys from
           (type=str)

lookup(self, hostname)

Find a hostkey entry for a given hostname or IP. If no entry is found, None is returned. Otherwise a dictionary of keytype to key is returned.
Parameters:
hostname - the hostname to lookup
           (type=str)
Returns:
keys associated with this host (or None)
           (type=dict(str, PKey))

Static Method Details

hash_host(hostname, salt=None)

Return a "hashed" form of the hostname, as used by openssh when storing hashed hostnames in the known_hosts file.
Parameters:
hostname - the hostname to hash
           (type=str)
salt - optional salt to use when hashing (must be 20 bytes long)
           (type=str)
Returns:
the hashed hostname
           (type=str)

Generated by Epydoc 2.1 on Sun Feb 19 23:24:07 2006 http://epydoc.sf.net