Python ssh free Login

Source: Internet
Author: User

#!/usr/bin/env python

Import Os,sys

Import Pexpect

Import time


def Pai (LINE,PASSWD):

Try

cmd = "Ssh-copy-id-i/root/.ssh/id_rsa.pub [email protected]%s"%line # #命令

Child = Pexpect.spawn (cmd) # #铺抓命令

I=child.expect ([' Continue ', ' Password: ']) # #铺抓弹窗

If i==0: # #判断位置参数

Child.sendline (' yes ')

Child.sendline (passwd)

Return Child.read () # #返回值

Except Exception,e: # #异常处理

Return ' login '


Passwd= "Fh123tianluo"


f = open ("/root/host_ip", ' R ') #打开文件

S1 = []


For line in F.readlines (): #将文件的IP加入到列表s1

S1.append (Line.strip ())

F.close ()


Print (S1)


For I In (S1): #调用这个Pai方法并且执行

Print (' Yeye ', i)

AA = Pai (I,PASSWD)

Print (' Last ', AA)



Python ssh free Login

Related Article

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.