#!/usr/bin/python
#-- coding:utf-8 --
author = “Replaceroot”

import paramiko

private_key = paramiko.RSAKey.from_private_key_file(‘id_rsa102.txt’)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(hostname = ‘192.168.0.104’, port=22, username=“root”, pkey=private_key)

stdin, stdout, stderr = ssh.exec_command(‘ifconfig’)

result = stdout.read()
print(result.decode())
ssh.close()

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐