Distribution of public keys based on Paramiko to other machines, there's a shortage of places to look.
#-*- coding: utf-8 -*-#!/usr/bin/python import osimport paramikoimport Threadingdata= ' Ssh-rsa aaaab3nzac1yc2eaaaabiwaaaqeavqfqvw1jjyhrvgqyjbclstwnx0q/x+ichdatg0mvj5nrew08eoeiy4 /rscsuiqamlaiapta0smn5yg9vp0z4esfqmeye3kubx4r+y+ Xvimil2y3ftkmo9a5ecoegwmjcfognboa9nwylpf1yahyhjuvvmqkjc8vgzro5gtumaewam509l5tuv4olr6dyzdhhssxkpewdpsfubseg2pumtova /n9fgcij1k7z1nv2slwxrosnedo20dyibnr0f1pzh6emhilduwohs5n9jboryqaqasq3q9o421pvcov6pftfpim9wpn+ Zrp7pq6outxdxixknjfmjl15iob03sxkew== [email protected] ' Def ssh2 (ip,username,passwd,cmd): try: paramiko.util.log_to_file (' paramiko_____ ___.log ') ssh = paramiko. Sshclient () ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) #ssh. Connect (ip,22,username,passwd,allow_agent =false,look_for_keys=false,timeout=5) ssh.connect (ip,22,username,passwd,timeout=5) for m in cmd: stdin, stdout, stderr = ssh.exec_command (M) print stdout.readlines () sftp = ssh.open_sftp () remote_file = sftp.file ('/root/.ssh/ Authorized_keys ', ' WB ') remote_ file.set_pipelined (True) remote_ File.write (data) print '%s\tok\n '% (IP) sftp.cloSE () ssh.close () except : print '%s\terror\n '% (IP) if __name__== ' __main__ ': username= "root" passwd= "[email protected]" cmd=[' if (! -d /root/.ssh/); Then mkdir /root/.ssh/;fi '] #cmd =[ ' W '] threads=[] print "Begine ..." For i in range (200,217): ip= ' 192.168.50. ' +str (i) #print ip begine=threading. Thread (target=ssh2,args= (ip,username,passwd,cmd)) #ssh2 (IP, USERNAME,PASSWD) begine.start ()
One distribution small script based on Python