1

I want to connect to a device via SSH with Paramiko (python library) but my device needs 2 step connection as below picture:

enter image description here

here is my code :

import paramiko
ssh_client =paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname='10.240.235.167',username='cli', password='')


stdin, stdout, stderr = ssh_client.exec_command('admin')
stdin, stdout, stderr = ssh_client.exec_command('Admin123\n')
stdin.write('admin123\n')
stdin,stdout,stderr=ssh_client.exec_command('my command')

but it's not working, I want to know how to connect and store result of my command.

13
  • what is not working? Please share the error or stacktrace you have got. Commented Jan 1, 2020 at 14:16
  • UserWarning: implicit cast from 'char *' to a different pointer type: will be forbidden in the future (check that the types are as you expect; use an explicit ffi.cast() if they are correct) self._backend._ffi.from_buffer(data), len(data) [] Commented Jan 1, 2020 at 14:25
  • my problem is first I should login as cli and I don't know how to implement it with paramiko Commented Jan 1, 2020 at 14:51
  • 1
    My answer also explains that you cannot use exec_command and shows that you need to send the command to the "shell". Commented Jan 1, 2020 at 17:54
  • 1
    I have added an example code to my answer. Commented Jan 1, 2020 at 18:14

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.