Load host entries from the known_hosts file(s) before writing the file from RAM to disk. Avoids loss of host entries in case other SSH clients have written to the known_hosts file(s) meanwhile.

This commit is contained in:
Mike Gabriel 2012-10-12 09:50:51 +02:00 committed by Jeff Forcier
parent 080bece258
commit 81f87f1d5e
1 changed files with 6 additions and 0 deletions

View File

@ -186,6 +186,12 @@ class SSHClient (object):
@raise IOError: if the file could not be written
"""
# update local host keys from file (in case other SSH clients
# have written to the known_hosts file meanwhile.
if self.known_hosts is not None:
self.load_host_keys(self.known_hosts)
f = open(filename, 'w')
f.write('# SSH host keys collected by paramiko\n')
for hostname, keys in self._host_keys.iteritems():