@@ -46,15 +46,13 @@ def __init__(self, conn_params: ConnectionParams):
4646 self .host = conn_params .host
4747 self .ssh_key = conn_params .ssh_key
4848 self .port = conn_params .port
49+ self .ssh_cmd = ["-o StrictHostKeyChecking=no" ]
4950 if self .ssh_key :
50- self .ssh_cmd = ["-i" , self .ssh_key ]
51- else :
52- self .ssh_cmd = []
51+ self .ssh_cmd += ["-i" , self .ssh_key ]
5352 if self .port :
54- self .ssh_cmd = ["-p" , self .port ]
53+ self .ssh_cmd + = ["-p" , self .port ]
5554 self .remote = True
5655 self .username = conn_params .username or self .get_user ()
57- self .add_known_host (self .host )
5856 self .tunnel_process = None
5957
6058 def __enter__ (self ):
@@ -78,16 +76,6 @@ def close_ssh_tunnel(self):
7876 else :
7977 print ("No active tunnel to close." )
8078
81- def add_known_host (self , host ):
82- known_hosts_path = os .path .expanduser ("~/.ssh/known_hosts" )
83- cmd = 'ssh-keyscan -H %s >> %s' % (host , known_hosts_path )
84-
85- try :
86- subprocess .check_call (cmd , shell = True )
87- logging .info ("Successfully added %s to known_hosts." % host )
88- except subprocess .CalledProcessError as e :
89- raise Exception ("Failed to add %s to known_hosts. Error: %s" % (host , str (e )))
90-
9179 def exec_command (self , cmd , wait_exit = False , verbose = False , expect_error = False ,
9280 encoding = None , shell = True , text = False , input = None , stdin = None , stdout = None ,
9381 stderr = None , get_process = None , timeout = None ):
0 commit comments