Netmiko SSH jump box server

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 11:27 AM
I’m trying to implement a Python script to collect to some outputs from Switches and routers. My problem is that I need to go through a proxy server. The flow is like this:
Personal Mac ----1-----> jumpbox ----2----> Nexus SW
Step 1:
- Authentication via SSH Key and password
Step 2:
- Authentication via username/password
I’m using SSH File config, as below. Using this SSH File, I can connect to the jumphost so I don’t think the issue is on the first step:
host VPS
IdentityFile <keyfile>
user <username>
hostname <IP>
port 22
host * !VPS # Use the SSH proxy for all endpoints
ProxyCommand ssh VPS nc %h %p
When I try to connect to a switch using the script below, I’m getting the error below it:
<PYTHON SCRIPT>
from netmiko import ConnectHandler
from getpass import getpass
import logging
logging.basicConfig(filename='test.log', level=logging.DEBUG)
logger = logging.getLogger("my_log")
logger.debug('This message should go to the log file')
device = {
'device_type': 'cisco_ios',
'host': 'HOST',
'username': '<device username>',
'password': '#######,
'ssh_config_file': 'ssh_config.txt',
'global_delay_factor': 4
}
net_connect = ConnectHandler(**device)
output = net_connect.send_command("show users")
print(output)
/usr/local/bin/python2.7 "/Users/zammes/PycharmProjects/Network Automation/proxy_test.py"
Traceback (most recent call last):
File "/Users/zammes/PycharmProjects/Network Automation/proxy_test.py", line 19, in <module>
net_connect = ConnectHandler(**device)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 190, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/netmiko/base_connection.py", line 245, in __init__
self.establish_connection()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/netmiko/base_connection.py", line 738, in establish_connection
self.remote_conn_pre.connect(**ssh_connect_params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/client.py", line 392, in connect
t.start_client(timeout=timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/transport.py", line 545, in start_client
raise e
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Process finished with exit code 1
Is there someone that could help me with it?
- Labels:
-
Network Programmability
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 09:55 PM
It's a bit of an old post but I randomly popped into it.
1). Can you ssh into this 'HOST' from the same machine? Is the DNS resolving properly? If not, just use IP address as this error indicates that you simply cant get there.
2). Why are you using 2.7? It's 2019 (well you posted it in 2018) get onto 3.x ;)
3). There is a special method to get onto terminal server using netmiko
