-1

I got an issue when using paramiko to ssh (user+pass, no pubkey used) to a apc pdu(Net Mgmt Card).The same code works if it connects to a cisco switch. Is it something related to low python version? or I should tune the ssh parameters for this particular low profile device (apc pdu)? Any of your suggestion is highly appreciated!

code snippet

import paramiko
def ssh_connect(ip,user,password,comm):
  client = paramiko.SSHClient()
  client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  client.connect(ip,username=user,password=password,allow_agent=False,look_for_keys=False)
  session = client.get_transport().open_session()
  if session.active:
    stdin, stdout, stderr = client.exec_command(comm)
    print(stdout.read().decode())
  return

ssh_connect('10.1.1.10','bob.lee','abcdefg','whoami')

Errors:

/home/boblee/.local/lib/python2.7/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
  from cryptography.hazmat.backends import default_backend
Traceback (most recent call last):
  File "pdu.py", line 14, in <module>
    ssh_connect('10.1.1.10','boblee','abcdefg','whoami')
  File "pdu.py", line 8, in ssh_connect
    stdin, stdout, stderr = client.exec_command(comm)
  File "/home/boblee/.local/lib/python2.7/site-packages/paramiko/client.py", line 510, in exec_command
    chan = self._transport.open_session(timeout=timeout)
  File "/home/boblee/.local/lib/python2.7/site-packages/paramiko/transport.py", line 879, in open_session
    timeout=timeout,
  File "/home/boblee/.local/lib/python2.7/site-packages/paramiko/transport.py", line 1006, in open_channel
    raise e
EOFError

1 Answers1

0

Your script (only added #!/usr/bin/env python and changed the ip, user, pw & command) works on my setup:

  • Host and guest both running Arch Linux x86 64bit
  • Host running Python 3.10.1 (using venv).
  • Command I ran: ls ~

It looks like you're running your script with Python 2 (as per your error traceback). If you have a Python 3 version available on your system, give it a try (many system have python referencing to Python 2 and python3 to v 3.x).

niko
  • 5,253
  • 1
  • 12
  • 32