0

My goal is to connect to a server using ssh and then ssh again into a router in that server using paramiko.

This is what I have tried.

username, password, port = credentials...
hostname = 1st server
router = router server
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy)
client.connect(hostname, port = port, username = username, password = password)
print("connecting to {} from {} as {}".format(router, hostname, username))
# Calls syslog.py from the server
cmd = "ssh {}@{}".format('root', router)
print('command = {}'.format(cmd))
stdin, stdout, stderr = client.exec_command(cmd, get_pty = True)
stdin.write(pw here)
stdin.flush()
stdin.write('show ?\n')
stdin.flush()

client.close()

I am connecting into the server and then the router and run show ? in the router.

show ? is supposed to give me a list of all possible commands starting with show. However, when I run the script, it gives me

connecting to <router ip> from <1st server> as root
command = ssh root@<router ip>

and then it just ends without showing the result of show ?

It's really hard to catch the issue because it doesn't show an error.

Any help please?

20
  • Might be helpful: gist.github.com/tintoy/443c42ea3865680cd624039c4bb46219 Commented Jul 31, 2019 at 5:14
  • I tried to use it, but for any command in the router, it gives me b"% Invalid input detected at '^' marker.\r" Commented Jul 31, 2019 at 5:22
  • You are not reading the command output. See Paramiko: read from standard output of remotely executed command. Commented Jul 31, 2019 at 5:24
  • Not to mention that running ssh on the jump server is rather a hack. You better use a port forwarding, as I have suggested you already: Connecting to a server via another server using Paramiko. Commented Jul 31, 2019 at 5:25
  • @MartinPrikryl I've tried, but the credentials didn't work for some reason. This is the command that I used to run that: python forward.py -p 22 -u <name of 1st server> -P <pw for the router> -r <router ip> then I typed the password for the 1st server in the following Enter SSH password: input Commented Jul 31, 2019 at 5:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.