From 81f87f1d5eb4fa89472114f45faa3a994fc7db7d Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Fri, 12 Oct 2012 09:50:51 +0200 Subject: [PATCH] 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. --- paramiko/client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/paramiko/client.py b/paramiko/client.py index 5b71958..4fa28e5 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -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():