0
import time
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('x.x.x.x',22, username='root', password='12345')
ssh_stdin ,ssh_stdout, ssh_stderr = ssh.exec_command('ssh -tt root@y.y.y.y')
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('test@123')
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('!pwd')

This is the code i want to run i want to login to shell terminal of x.x.x.x server & ssh to server y.y.y.y & excute several commands. please help me on this

  • Actually this one -https://stackoverflow.com/questions/35304525/nested-ssh-using-python-paramiko solved my problem to certain extent. But i'm stuck now rsa key passing .it say no such file – nskniranga1127 Aug 16 '20 at 07:32

1 Answers1

0

Try sshpass package. The problem looks like that after you execute the first command, it is expecting the password, but the command is not returned to the client.

You can try installing sshpass first into x.x.x.x, and then use it like this:

sshpass -p 'YourPassword' ssh user@y.y.y.y

to login to y.y.y.y.

Anirudh Bagri
  • 2,346
  • 1
  • 21
  • 33
  • Hi, Thank you for this. Anyway after login to 2nd device , is it possible execute commands using ssh.exec_command. it has a different shell interface commands are little different i want to get the output of these commands to python ouput – nskniranga1127 Aug 15 '20 at 07:33