Fixes in ssh paramiko

This commit is contained in:
Antonio de la Rosa 2025-05-15 02:03:12 +02:00
parent 6cd4598708
commit 7c4895e32c
4 changed files with 69 additions and 40 deletions

View file

@ -13,7 +13,7 @@ class Task:
#($server='', $ssh_user='root', $ssh_key_priv='./ssh/id_rsa', $ssh_key_password='', $ssh_path='leviathan', $mysql_conn=false)
def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}, port=22):
def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key=None, remote_path='pastafari2', task_id=0, data={}, port=22):
self.config=config_task
@ -136,6 +136,9 @@ class Task:
"""
#if not os.path.isfile(self.private_key):
if check_ssh_host.lookup(self.server)==None:
# Be tolerant for the first connect with hostkey policy
@ -158,7 +161,11 @@ class Task:
#self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, pkey=rsa, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, key_filename=self.private_key, passphrase=self.password_key, timeout=None, allow_agent=False, look_for_keys=False, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
if self.remote_password:
self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, timeout=None, allow_agent=False, look_for_keys=False, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
else:
self.ssh.connect(self.server, port=self.port, username=self.remote_user, key_filename=self.private_key, passphrase=self.password_key, timeout=None, allow_agent=False, look_for_keys=False, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
if add_host:
host_key.save(self.config.ssh_directory+'/known_hosts')