How to Connect SSH Using Python and Netmiko?

By Published On: November 18, 20191.3 min readViews: 265

Recently I’ve needed to automate some tasks in my daily operational job by accessing a juniper firewall (Legacy NetScreen) and modify rules on a daily basis, so I’ve made my deep internet research and I’ve found an easy way to connect ssh using python and Netmiko library.

Finally, I could automate tasks on my firewall like adding, deleting or modifying configuration without wasting my time.

Let’s start with the installation steps:

  1. Installing python 3
  2. Then install pip
  3. Finally, Install Netmiko

1. Install Python 3

The first and easiest step, you just click here and install python normally from your windows machine.

2.Install pip

  1. Before installing pip we have to check that python 3 is installed properly, by just opening cmd and type python to find Python 3.8.0 (v3.7.0:1bf9cc5093, Nov 17 2019, 04:59:51)
    [MSC v.1914 64 bit (AMD64)] on win32
  2. Download pip package by clicking here .
  3. Start installing by opening the Command Prompt and navigate to the get-pip.py file.
  4. Run the following command: python get-pip.py

3.Install Netmiko

Similar to pip installation we are going to:

  1. Open cmd and type pip install netmiko.
  2. Find out simple code for show command from Netmiko documentation.
  3. Also here there is a simple code to send configuration command from Netmiko documentation.

Finally, we can connect ssh using python and able to test, show commands and also configure our firewall.

If you’ve any question just drop it in the comment section, and I’ll be more than happy to support you.

Thank you for reading!

Share this article

Written by : Ahmed Hesham AbdElHalim

Leave A Comment