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?