One distribution small script based on Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.