当前位置:   article > 正文

python paramiko模块 用密钥传输

paramiko 设定指定交换密钥
VM_129_78_suse:/home/remote_paramiko # cat remote.py 
#!/usr/bin/env python

import paramiko

linux_cmd = "uptime"
#linux_cmd = "df -Th"


haiwai_ipaddress = {'14.215.177.39','114.215.177.139','14.205.177.39','114.215.77.39','14.215.177.30'}

for i in haiwai_ipaddress: 
    print i
    private_key = paramiko.RSAKey.from_private_key_file('/home/remote_paramiko/id_rsa')
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname=i, port=33263, username='root')
    stdin, stdout, stderr = ssh.exec_command(linux_cmd)
    result_out = stdout.readlines()
    for item in result_out:
        print('\033[1;32;40m')
        print item
        print('\033[0m')

    result_err = stderr.readlines()
    for item in result_err:
        print('\033[1;32;40m')
        print item
        print('\033[0m')

    ssh.close()

 

转载于:https://www.cnblogs.com/rayong/p/7802529.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/603510
推荐阅读
相关标签
  

闽ICP备14008679号