首页 > 编程语言 > 详细

python之路-模块安装 paramiko

时间:2016-01-08 00:10:21      阅读:288      评论:0      收藏:0      [点我收藏+]

paramiko介绍(全是洋文,看不懂啊,赶紧有道翻译吧,等有朝一日,我去报个华尔街):

"Paramiko" is a combination of the esperanto words for "paranoid" and "friend". Its a module for Python 2.6+ that implements the SSH2 protocol for secure (encrypted and authenticated) connections to remote machines. Unlike SSL (aka TLS), SSH2 protocol does not require hierarchical certificates signed by a powerful central authority. You may know SSH2 as the protocol that replaced Telnet and rsh for secure access to remote shells, but the protocol also includes the ability to open arbitrary channels to remote services across the encrypted tunnel (this is how SFTP works, for example).

It is written entirely in Python (no C or platform-dependent code) and is released under the GNU Lesser General Public License (LGPL).

The package and its API is fairly well documented in the "doc/" folder that should have come with this archive.

github地址:

https://github.com/paramiko/paramiko

 

paramiko安装:

安装环境:ubuntu-14.04.2

1、首先确定一下gcc是否安装,如果没有安装的话需要安装一下

# 安装命令
sudo apt-get install gcc

2、需要安装PyCrypto

下载地址:https://www.dlitz.net/software/pycrypto/
# 我下载的是pycrypto-2.6.1.tar.gz

tar -zxf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1/
python setup.py build
sudo python setup.py install

检查是否安装成功:
进入python解释环境下导入Crypto模块,没有报错说明安装成功:
>>> import Crypto

3、安装paramiko

sudo pip install paramiko
如果没有安装pip的可以参考:http://www.cnblogs.com/CongZhang/p/5111195.html

检查paramiko是否安装成功:
进入python解释器环境下导入paramiko模块,没有报错说明安装成功:
>>> import paramiko

4、牛刀小试

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 本程序在python 2.7下运行

import paramiko

def ssh_connect(ip, port, user_name, passwd, shell):
    ssh = paramiko.SSHClient()
    # paramiko.util.log_to_file(/dev/null)
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, port, username=user_name, password=passwd)
    stdin, stdout, stderr = ssh.exec_command(shell)     # 执行命令

    print stdout.readlines()    # 输出执行命令的正确输出结果
    print stderr.readlines()    # 输出执行命令的错误输出结果

ip = 1.1.1.1  # 服务器ip地址
port = 22     # 服务器ssh连接端口
user_name = xxxx     # ssh登陆帐号
passwd = xxxxx   # ssh登陆密码
shell = sudo ifconfig     # 执行命令
ssh_connect(ip, port, user_name, passwd, shell)

python之路-模块安装 paramiko

原文:http://www.cnblogs.com/CongZhang/p/5111180.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!