Python Pxssh the implementation of batch issued SSH public key file

Source: Internet
Author: User
Tags scp file

#!/usr/bin/env python "need to pay attention to a few questions 1, Pxssh class, exist in the Pexpect module, if you do not install this module installed on its own, if this module already exists, but there is no pxssh class, verified, That is, the version of this module is too low. Please update to the new version 2, about the command in Os.system (), this is the execution of a shell command, and itself sshpass  is implemented in the execution of the SCP file is to automatically enter the account password of the peer machine, if the Sshpass is not installed, please install it yourself. "' #!/usr/bin/env pythonfrom pexpect import pxsshimport osusername=" root "passwd=" 1qaz #EDC "Try:    for i in range (151,156):         s = pxssh.pxssh ()         ipaddr=  ' 192.168.100.%s '  % i     #生成一个完整的IP地址          os.environ[' IP ']=str (ipaddr)      #变量互换, Python variables can be obtained in the shell          s.login (IPADDR,USERNAME,PASSWD)       #登录主机 (IP, user, password)          print  ' host:%s login complete! '  % ipaddr        s.sendline (' mkdir -p /root/.ssh/')      #运行命令, create a hidden ssh directory          os.system (' sshpass -p 1qaz#edc scp /root/.ssh/ Authorized_keys [email protected] $ip:/root/.ssh/')      #下发公钥文件: Authorized_keys         print  ' host:%s task running ok! '  % ipaddr        s.prompt ()      #匹配系统提示符         s.logout ()      #断开SSH连接except  pxssh. exceptionpxssh, e:    print  "Pxssh failed on login"      print str (e)


This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1873416

Python Pxssh the implementation of batch issued SSH public key file

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.