Authenticating using public-private keys with netmiko
In all recipes so far, we have used a combination of username and password to authenticate ourselves against the device. A different approach employed quite frequently, and sometimes even required by certain audit requirements, is that we use public-private keys to authenticate.
In Chapter 2, Connecting to Network Devices via SSH Using Paramiko, we saw that Paramiko supports the usage of keys instead of a username/password combination to authenticate. As netmiko is built on top of Paramiko, we can also do this conveniently with netmiko.
In this recipe, we'll see how to use a private key to authenticate against a device and issue a command.
Getting ready
Open your code editor and start by creating a file called auth_key.py
. Next, navigate your terminal to the same directory that you just created the auth_key.py
file in.
Make sure that the device you are using is configured to use public-private key authentication...