python 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()
贵有恒,何必三更起五更睡;最无益,只怕一日暴十寒