netmiko: Exception while ssh into IOS devices with public keys

Received this exception “paramiko.transport:SSHException: Illegal info request from server” for the following code:

net_device = {
        'device_type': 'cisco_ios',
        'ip': '<REMOVED>',
        'username': '<REMOVED>',
        'use_keys': True,
        'key_file': '<REMOVED>/.ssh/id_rsa',
        'port': 22,
        'allow_agent': True #regardless of value 
}

import netmiko
import logging

logging.basicConfig(level=logging.NOTSET)

net_connect = netmiko.ConnectHandler(**net_device)
show_version = net_connect.send_command('show version')
print show_version

Same code works with JUNOS/NXOS but not with IOS devices.

DEBUG:paramiko.transport:userauth is OK ERROR:paramiko.transport:Exception: Illegal info request from server ERROR:paramiko.transport:Traceback (most recent call last): ERROR:paramiko.transport: File “<REMOVED>/cicd/venv/local/lib/python2.7/site-packages/paramiko/transport.py”, line 1791, in run ERROR:paramiko.transport: self.auth_handler._handler_table[ptype](self.auth_handler, m) ERROR:paramiko.transport: File “<REMOVED>/cicd/venv/local/lib/python2.7/site-packages/paramiko/auth_handler.py”, line 575, in _parse_userauth_info_request ERROR:paramiko.transport: raise SSHException(‘Illegal info request from server’) ERROR:paramiko.transport:SSHException: Illegal info request from server ERROR:paramiko.transport: DEBUG:paramiko.transport:Trying discovered key <REMOVED> in <REMOVED>/.ssh/id_rsa Traceback (most recent call last): File “con_pub.py”, line 17, in <module> net_connect = netmiko.ConnectHandler(**net_device) File “<REMOVED>cicd/venv/local/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py”, line 96, in ConnectHandler return ConnectionClass(*args, **kwargs)

Python 2.7.3 cffi (1.9.1) cryptography (1.6) enum34 (1.1.6) idna (2.1) ipaddress (1.0.17) netmiko (1.1.0) paramiko (2.0.2) pip (9.0.1) pyasn1 (0.1.9) pycparser (2.17) PyYAML (3.12) scp (0.10.2) setuptools (29.0.1) six (1.10.0) wheel (0.29.0)

paramiko_logs.txt Openssh_works_cisco1.25_debug_logs.txt

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

@sjtarik I was able to get it working to a Cisco IOS device (Cisco 881) using the following:

#!/usr/bin/env python
from netmiko import ConnectHandler
from getpass import getpass

ip_addr = input("Enter IP Address: ")

device = { 
    'device_type': 'cisco_ios',
    'ip': ip_addr,
    'username': 'testuser',
    'use_keys': True,
    'key_file': '/home/gituser/.ssh/test_rsa',
    'port': 22, 
} 

net_connect = ConnectHandler(**device)
output = net_connect.send_command_expect("show version")
print(output)