diff --git a/transfer/ssh.py b/transfer/ssh.py index 9359a16..3341d4c 100644 --- a/transfer/ssh.py +++ b/transfer/ssh.py @@ -60,7 +60,7 @@ def check_ssh_connectivity(host, user, port, key_path=None, timeout=10): identity = f"-i '{key_path}'" if key_path and os.path.isfile(key_path) else "" cmd = f"ssh {identity} -p {port} -o ConnectTimeout={timeout} -o BatchMode=yes -o StrictHostKeyChecking=accept-new {user}@{host} 'echo migrate-ok'" - r = run(cmd, check=False, capture=True) + r = run(cmd, check=False, capture=True, timeout=30) if r.returncode == 0 and "migrate-ok" in r.stdout: return (True, r.stdout, r.stderr) return (False, r.stdout, r.stderr) @@ -108,7 +108,12 @@ def ssh_copy_id(host, user, port, pubkey_path): """Копирует публичный ключ на target через ssh-copy-id или вручную.""" if exists("ssh-copy-id"): info("Копируем публичный ключ через ssh-copy-id ...") - r = run(f"ssh-copy-id -p {port} -i '{pubkey_path}' {user}@{host}", check=False) + # Добавляем SSH опции чтобы избежать зависания + r = run( + f"ssh-copy-id -p {port} -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new -i '{pubkey_path}' {user}@{host}", + check=False, + timeout=60 + ) if r.returncode == 0: success("Ключ добавлен на target через ssh-copy-id") return True