Netmiko MikroTik RouterOS SSH 密钥登录示例
在我们之前的示例 Netmiko MikroTik RouterOS 最小示例 中,我们展示了如何使用 netmiko 和基于密码的登录登录到 RouterOS 设备。
mikrotik_ssh_key_login.py
#!/usr/bin/env python3
from netmiko import ConnectHandler
import os.path
mikrotik = {
'device_type': 'mikrotik_routeros',
'host': '192.168.88.1',
'username': 'admin',
'key_file': os.path.expanduser("~/.ssh/id_mikrotik"),
}
with ConnectHandler(**mikrotik) as mikrotik_connection:
print(mikrotik_connection.send_command(f'/system/identity/print', cmd_verify=False))示例输出:
mikrotik_identity_output.txt
name: MySwitch01Check out similar posts by category:
MikroTik, Networking, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow