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
   注意嘍,這個文件可不要誰都給嘍
   你的密碼在裏面呢python

相關文章
相關標籤/搜索