paramiko免密登陆

paramiko免密登陆

# -*- coding: utf-8 -*-
import paramiko
 
 
pkey='D:/pycharm_workspace/testpy/ssh_paramiko_demo/id_rsa'
key=paramiko.RSAKey.from_private_key_file(pkey)
paramiko.util.log_to_file('paramiko.log')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# ssh.load_system_host_keys()
ssh.connect('192.168.*.*',username = 'root',pkey=key)
stdin,stdout,stderr=ssh.exec_command('hostname')
print(stdout.read())
stdin,stdout,stderr=ssh.exec_command('ls')
print(stdout.readlines())
posted @ 2021-09-22 16:17  Teddy_boy  阅读(278)  评论(0编辑  收藏  举报