0

Currently I have 2 servers A and B. In order to access server B I have to initiate a session towards server A then from there I can access to server B using SSH as well.

Currently I am using python 3.10 and am using Paramiko to do the first SSH and the second server I am accessing it using executing commands on the SSH session as in below code snippet.

def _init_() -> None:
    self.ssh = paramiko.SSHClient()
    self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

def connect(self,IP,port,username,OTP):    
    self.ssh.connect(str(IP), str(port), str(username), str(OTP))
    self.chan = self.ssh.invoke_shell()

then to reach the other server I am currently using the below

self.chan.send("ssh " + str(sshphrase) + '\n')
while self.chan.recv_ready():
    self.buff = self.chan.recv(4096).decode("utf-8")
    print (self.buff)

Is there a better way to have like another Paramiko instance created based on a previous one instead of doing SSH by sending commands to the initial Paramiko SSHClient?

The above is currently working for me but causing a lot of delays and I am lacking control on sessions especially when I need to perform additional SSH layers within the script.

Ali Kaissi
  • 44
  • 8

0 Answers0