码迷,mamicode.com
首页 > 编程语言 > 详细

python ssh登录

时间:2016-09-29 17:56:52      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:

3. 编写linkssh.py
 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# filename: pexpect_test.py
‘‘‘
Created on 2012-03-31
 
@author: qvb3d
‘‘‘
import pexpect
 
if __name__ == ‘__main__‘:
    user = ‘root‘
    ip = ‘192.168.1.8‘
    mypassword = ‘不能写了‘
    child = pexpect.spawn(‘ssh %s@%s‘ % (user,ip))
    child.expect (‘password:‘)
    child.sendline (mypassword)
    child.interact()     # Give control of the child to the user.
 
    pass
 
保存
 
4.执行 python linkssh.py
 
5.这时你就可自动进入ssh
   注意喽,这个文件可不要谁都给喽
   你的密码在里面呢

python ssh登录

标签:

原文地址:http://www.cnblogs.com/poerli/p/5920566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!