Connecting To A Server Via Another Server Using Paramiko
I am trying to get into a server using Paramiko and then get into a router that's in the server and then run a command. However, I am not getting a password input for the router an
Solution 1:
First, you better use port forwarding (aka SSH tunnel) to connect to a server via another server.
See Nested SSH using Python Paramiko.
Anyway to answer your literal question:
OpenSSH
ssh
needs terminal when prompting for a password, so you would need to setget_pty
parameter ofSSHClient.exec_command
(that can get you lot of nasty side effects).Then you need to write the password to the command (
ssh
) input.And then you need to write the (sub)commands to the
ssh
input. See Execute (sub)commands in secondary shell/command on SSH server in Python Paramiko.
stdin, stdout, stderr = client.exec_command(cmd, get_pty=True)
stdin.write('password\n')
stdin.flush()
stdin.write('subcommand\n')
stdin.flush()
But this approach is error prone in general.
Post a Comment for "Connecting To A Server Via Another Server Using Paramiko"