Python learning | Part 24 |Netmiko Cisco SSH using RSA keypair for automation | without password

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
๐—™๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ:
๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—ณ๐—ผ๐—ฟ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—จ๐—ฑ๐—ฒ๐—บ๐˜† ๐—–๐—น๐—ฎ๐˜€๐˜€: ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง
๐‘ซ๐’Š๐’”๐’„๐’๐’–๐’๐’•๐’†๐’… ๐‘น๐’†๐’‡๐’†๐’“๐’“๐’‚๐’ ๐‘ณ๐’Š๐’๐’Œ:

To stay updated with my latest videos Please subscribe to my channel by clicking below

This video demonstrates how to initiate SSH Cisco device using RSA keypair from Netmiko. This can help in automating configuration tasks.
This includes
How to generate rsa keypair using ssh-keygen in linux
how to add the key in Cisco router for trusting the user public key
How to use 'use keys' and 'key_file' in netmiko for sh without password
Script

ssh-keygen -b 2048 -t rsa

The maximum line length at the Cisco CLI is 254 characters, but it's convenient to wrap smaller than this so that it fits on a terminal line.
show run

ip ssh pubkey-chain
username admin1

IP_LIST = open('20_devices')
for IP in IP_LIST:
print ('\n'+ IP.strip() + ' \n' )
RTR = {
'ip': IP,
'username': 'admin1',
'use_keys': True,
'key_file': '/data/05_PYTHON_DEMO/SSH_KEY/admin1',
'device_type': 'cisco_ios',
}
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

Very clear and informative. Thank you very much.

timaarons
ะะฒั‚ะพั€

Hi Bro ..it will be good if you show how to use windows 10 to do ssh from terminal using private key

prasadtalekar
ะะฒั‚ะพั€

This was good stuff and very helpful thank you for taking the time. I did have trouble with netmiko and ended up reading that paramiko/netmiko only deals with old PEM format. So I ended up making the key pair as such: ssh-keygen -m PEM -t rsa -b 2048 -f admin1.
This got me around the Exception errors.
Not sure why it worked on the video using (ssh-keygen -b 2048 -t rsa) ???

If your using napalm there is support as well for an SSH RSA key pair solution using the " optional_args".

quick example:
Its a bit confusing at first but you only need two arguments and you leave the password blank or fill it in with superfluous characters.
optional_args = {'use_keys': 'True', 'key_file': '/home/john/SSH_KEY/admin1'}
iosvl3 = driver('172.16.9.2', 'admin1', '***', optional_args = optional_args)

jaemercado
ะะฒั‚ะพั€

Sir, I can ssh into my switch using 'ssh -i' command but it failed using the script, and go to the SSHException, I don't know why, if the key file not working I should not ssh into the switch

chrisk
ะะฒั‚ะพั€

๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—ณ๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€(๐Ÿญ๐Ÿฎ๐Ÿฌ+ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
โ˜ธ๐—ฃ๐—น๐—ฒ๐—ฎ๐˜€๐—ฒ ๐—ณ๐—ผ๐—น๐—น๐—ผ๐˜„ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—š๐—ถ๐˜๐—›๐˜‚๐—ฏ ๐—ฃ๐—ฎ๐—ด๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐˜๐—ต๐—ฒ ๐—น๐—ฎ๐˜๐—ฒ๐˜€๐˜ ๐—ฐ๐—ผ๐—ฑ๐—ฒ๐˜€:
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—ก๐—ซ๐—”๐—ฃ๐—œ-๐—–๐—Ÿ๐—œ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป: ๐—ก๐—ฒ๐˜…๐˜‚๐˜€ ๐Ÿต๐—ธ :๐—ฃ๐—ฎ๐—ฟ๐˜€๐—ฒ ๐—ท๐˜€๐—ผ๐—ป ๐—ซ๐— ๐—Ÿ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐——๐—ฎ๐˜๐—ฎ
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป ๐˜๐—ผ ๐—ฃ๐—ฎ๐—ฟ๐˜€๐—ฒ ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐˜‚๐˜€๐—ถ๐—ป๐—ด ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ฅ๐—ฒ๐—ด๐—˜๐˜…:๐—ฟ๐—ฒ ๐—ง๐˜‚๐˜๐—ผ๐—ฟ๐—ถ๐—ฎ๐—น(๐Ÿญ๐Ÿฑ+ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ณ๐—ฎ๐—ฐ๐—ฒ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฎ๐—ฟ๐˜€๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐— ๐˜‚๐—น๐˜๐—ถ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ฅ๐—ฒ๐—ด๐—˜๐˜… ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜:๐—ง๐—ฎ๐—ฏ๐˜‚๐—น๐—ฎ๐˜๐—ฒ ๐—ง๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฒ๐˜…๐—ฎ๐—บ๐—ฝ๐—น๐—ฒ(๐Ÿฐ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—˜๐—ป๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐— ๐˜‚๐—น๐˜๐—ถ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ถ๐—ป ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด ๐—•๐—ฎ๐—ฐ๐—ธ๐˜‚๐—ฝ ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—ณ๐—ผ๐—ฟ ๐—ฃ๐—ฎ๐—ฟ๐—ฎ๐—น๐—น๐—ฒ๐—น ๐—ฒ๐˜…๐—ฒ๐—ฐ๐˜‚๐˜๐—ถ๐—ผ๐—ป:๐—ง๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ง๐˜‚๐˜๐—ผ๐—ฟ๐—ถ๐—ฎ๐—น(๐Ÿฐ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)
๐—ฃ๐—น๐—ฎ๐˜†๐—น๐—ถ๐˜€๐˜: ๐—”๐—ป๐˜€๐—ถ๐—ฏ๐—น๐—ฒ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ : ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐˜๐˜‚๐˜๐—ผ๐—ฟ๐—ถ๐—ฎ๐—น ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—˜๐˜…๐—ฎ๐—บ๐—ฝ๐—น๐—ฒ๐˜€(๐Ÿฏ๐Ÿฌ+ ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ๐˜€)

NetworkEvolution
ะะฒั‚ะพั€

i am using windows machine how can i generate Pub and Private Key ?

roger
ะะฒั‚ะพั€

I am getting RSA finger print mismatch. im using gns3 on ubuntu.

robinchandy