@@ -48,15 +48,13 @@ def __init__(self, conn_params: ConnectionParams):
4848 self .host = conn_params .host
4949 self .ssh_key = conn_params .ssh_key
5050 self .port = conn_params .port
51+ self .ssh_cmd = ["-o StrictHostKeyChecking=no" ]
5152 if self .ssh_key :
52- self .ssh_cmd = ["-i" , self .ssh_key ]
53- else :
54- self .ssh_cmd = []
53+ self .ssh_cmd += ["-i" , self .ssh_key ]
5554 if self .port :
56- self .ssh_cmd = ["-p" , self .port ]
55+ self .ssh_cmd + = ["-p" , self .port ]
5756 self .remote = True
5857 self .username = conn_params .username or self .get_user ()
59- self .add_known_host (self .host )
6058 self .tunnel_process = None
6159
6260 def __enter__ (self ):
@@ -80,16 +78,6 @@ def close_ssh_tunnel(self):
8078 else :
8179 print ("No active tunnel to close." )
8280
83- def add_known_host (self , host ):
84- known_hosts_path = os .path .expanduser ("~/.ssh/known_hosts" )
85- cmd = 'ssh-keyscan -H %s >> %s' % (host , known_hosts_path )
86-
87- try :
88- subprocess .check_call (cmd , shell = True )
89- logging .info ("Successfully added %s to known_hosts." % host )
90- except subprocess .CalledProcessError as e :
91- raise Exception ("Failed to add %s to known_hosts. Error: %s" % (host , str (e )))
92-
9381 def exec_command (self , cmd , wait_exit = False , verbose = False , expect_error = False ,
9482 encoding = None , shell = True , text = False , input = None , stdin = None , stdout = None ,
9583 stderr = None , get_process = None , timeout = None ):
0 commit comments