@@ -48,15 +48,13 @@ def __init__(self, conn_params: ConnectionParams):
4848self .host = conn_params .host
4949self .ssh_key = conn_params .ssh_key
5050self .port = conn_params .port
51+ self .ssh_cmd = ["-o StrictHostKeyChecking=no" ]
5152if 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 ]
5554if self .port :
56- self .ssh_cmd = ["-p" ,self .port ]
55+ self .ssh_cmd + = ["-p" ,self .port ]
5756self .remote = True
5857self .username = conn_params .username or self .get_user ()
59- self .add_known_host (self .host )
6058self .tunnel_process = None
6159
6260def __enter__ (self ):
@@ -80,16 +78,6 @@ def close_ssh_tunnel(self):
8078else :
8179print ("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-
9381def exec_command (self ,cmd ,wait_exit = False ,verbose = False ,expect_error = False ,
9482encoding = None ,shell = True ,text = False ,input = None ,stdin = None ,stdout = None ,
9583stderr = None ,get_process = None ,timeout = None ):