class paramiko.hostkeys.HostKeyEntry(hostnames=None, key=None)
Representation of a line in an OpenSSH-style "known hosts" file.
classmethod from_line(line, lineno=None)
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.
Lines are expected to not have leading or trailing whitespace. We don't bother to check for comments or empty lines. All of that should be taken care of before sending the line to us.
str
) -- a line from an OpenSSH known_hosts fileto_line()
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.
class paramiko.hostkeys.HostKeys(filename=None)
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
.
New in version 1.5.3.
__init__(filename=None)
Create a new HostKeys object, optionally loading keys from an OpenSSH style host-key file.
str
) -- filename to load host keys from, or None
add(hostname, keytype, key)
Add a host key entry to the table. Any existing entry for a
(hostname, keytype)
pair will be replaced.
check(hostname, key)
Return True if the given key is associated with the given hostname in this dictionary.
clear()
Remove all host keys from the dictionary.
static 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.
load(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")
.
If this method is called multiple times, the host keys are merged,
not cleared. So multiple calls to load
will just call add
,
replacing any existing entries and adding new ones.
str
) -- name of the file to read host keys fromIOError
-- if there was an error reading the filelookup(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. The keytype will be either "ssh-rsa"
or "ssh-dss"
.
save(filename)
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.
str
) -- name of the file to writeIOError
-- if there was an error writing the fileNew in version 1.6.1.