1

I am trying to connect to a server using SSH protocol through a jump server. When I connect through a terminal using a protocol, the jump server opens a shell and asks for a server number from the list of available servers provided, followed by a user or password. Using the library Paramiko.

My code:

import paramiko

client = paramiko.SSHClient()

client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client.connect(
    hostname="server_ip",
    username="user",
    password="pass",
    look_for_keys=False,
    allow_agent=False
)

com='1'

stdin, stdout, stderr = client.exec_command(com)

data = stdout.read() + stderr.read()

print(data.decode('utf-8'))

I get message:

Invalid target.

My shell on the jump server looks like this:
enter image description here

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

0

Your jump server probably shows the selection in an interactive shell session only. So you will have to use SSHClient.invoke_shell, what is otherwise not good thing to do when automating a connection.

See also What is the difference between exec_command and send with invoke_shell() on Paramiko?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992