Python 模块paramiko简单使用方法

Python模块paramiko可以实现用SSH登录服务器,并执行shell

#!/usr/bin/python

import sys
import paramiko

def pycmd(server, port, username, password, shellcmd):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()
    ssh.connect(server, port, username, password)
    stdin, stdout, stderr = ssh.exec_command(shellcmd)
    print stdout.readlines()
    ssh.close()

if _name__ == "__main__":
    pycmd("xxx.xxx.xxx.xxx", 22, "root", "password", sys.argv[1])

  


posted @ 2013-06-20 18:18  土豆王  阅读(425)  评论(0编辑  收藏  举报