From 8cdfc9855523c1c7e2ae916daed7ee7cb825818f Mon Sep 17 00:00:00 2001 From: konsthol Date: Thu, 16 Mar 2023 22:48:56 +0200 Subject: [PATCH] Landed. --- secdep.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/secdep.py b/secdep.py index 8dd2bdb..38e66f4 100755 --- a/secdep.py +++ b/secdep.py @@ -1443,22 +1443,28 @@ def ssh(): port = 22 username = "secdep" sshkey = SECDEP_SSH_PRIVATE_KEY - try: - ssh = paramiko.SSHClient() - ssh.load_system_host_keys() - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(ip, port=port, username=username, key_filename=sshkey) + ssh = paramiko.SSHClient() + ssh.load_system_host_keys() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(ip, port=port, username=username, key_filename=sshkey) + channel = ssh.get_transport() + if channel is not None: + channel = channel.open_session() + channel.get_pty() + channel.invoke_shell() while True: - try: - prompt = input("$> ") - if prompt == "exit": break - stdin, stdout, stderr = ssh.exec_command(prompt) - print(stdout.read().decode()) - except KeyboardInterrupt: - break + command = input('$> ') + if command == 'exit': break + channel.send((command + "\n").encode()) + while True: + if channel.recv_ready(): + output = channel.recv(1024) + print(output.decode()) + else: + time.sleep(0.5) + if not(channel.recv_ready()): + break ssh.close() - except Exception as ex: - print(str(ex)) # If -I -S or -G is passed, provider must be passed as well if args.listimages or args.listsizes or args.listlocations: