python ssh登录

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
   注意喽,这个文件可不要谁都给喽
   你的密码在里面呢

posted on 2016-09-29 17:08  Poer李  阅读(269)  评论(0编辑  收藏  举报

导航