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

"Paramiko" is a combination of the esperanto words for "paranoid" and "friend". It's 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.

罗总帮忙给翻译的(瞬间感觉我自己弱爆了):

"Paramiko" 是针对paranoid 和friend 的一种通用组合。对于python2.6以上的模块,这些模块能够应用SSH2安全协议。不像SSL(aka TLS)这种协议,SSH2协议并不要求有权威机构发布的等级证书。你可能知道SSH2作为一种协议已经代替了用于远程登录和执行一个远端命令这种安全登录模式来远程操作shells,但是协议也可以通过加密通道来打开任意的通道来实现远程服务(这就是SFTP怎样来实现工作的,例如)
它完全由python编写,并没有使用C或者依赖平台的代码方式),并且由LGPL授权发布新的版本。这个包和它的API很方便使用doc方式写入存档。

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..tar.gz tar -zxf pycrypto-2.6..tar.gz
cd pycrypto-2.6./
python setup.py build
sudo python setup.py install 检查是否安装成功:
进入python解释环境下导入Crypto模块,没有报错说明安装成功:
>>> import Crypto

注意:在python3编译pycrypto的时候需要先安装一下python3-dev 否则会报以下错误

此错误解决方法参考:http://gangmax.me/blog/2015/06/02/resolve-python-pycrypto-installation-error/

ubuntu安装方法:sudo apt-get install python3-dev

warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash._MD2' extension
x86_64-linux-gnu-gcc -pthread -fwrapv -Wall -Wstrict-prototypes -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python3.4m -c src/MD2.c -o build/temp.linux-x86_64-3.4/src/MD2.o
src/MD2.c:31:20: fatal error: Python.h: 没有那个文件或目录
#include "Python.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

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- -*- # 本程序在python .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 = # 服务器ssh连接端口
user_name = 'xxxx' # ssh登陆帐号
passwd = 'xxxxx' # ssh登陆密码
shell = 'sudo ifconfig' # 执行命令
ssh_connect(ip, port, user_name, passwd, shell)

python之路-模块安装 paramiko的更多相关文章

  1. Python的第三方模块安装

    python的第三方模块安装一般使用python自带的工具pip来安装. 1.在Windows下,在安装python时勾选[安装pip]和[添加python至环境变量]. 如果在python安装目录的 ...

  2. python在windows下安装paramiko模块和安装pycrypto模块(3步搞定)(转)

    Python中使用SSH需要用到OpenSSH,而OpenSSH依赖于paramiko模块,而paramiko模块又依赖于pycrypto模块,因此要在Python中使用SSH,我们需要先安装pycr ...

  3. python之路-pip安装

    pip类似RedHat里面的yum,安装Python包非常方便   安装pip方法: 1.安装环境:ubuntu-14.04.2 sudo apt-get install python-pip pyt ...

  4. Python的MySQLdb模块安装,连接,操作,增删改

    1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本     python -V   检查python版本 2. 安装mysql, 比如安装在/usr/local/my ...

  5. yum安装memcache,mongo扩展以及python的mysql模块安装

    //启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...

  6. python之mysqldb模块安装

    之所以会写下这篇日志,是因为安装的过程有点虐心.目前这篇文章是针对windows操作系统上的mysqldb的安装.安装python的mysqldb模块,首先当然是找一些官方的网站去下载:https:/ ...

  7. python之路 模块,序列化,迭代器,生成器

    一.模块 1.模块简介 模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py.模块可以被别的程序引入,以使用该模块中的函数等功能.这也是使用python标准库的方法. 类似于函数式编程和面向过 ...

  8. 百万年薪python之路 -- 模块

    1.自定义模块 1.1.1 模块是什么? 模块就是文件,存放一堆常用的函数和变量的程序文件(.py)文件 1.1.2 为什么要使用模块? 1.避免写重复代码,从文件级别组织程序,更方便管理 2.可以多 ...

  9. python之路--模块和包

    一 . 模块 ⾸先,我们先看⼀个老⽣常谈的问题. 什么是模块. 模块就是⼀个包含了python定义和声明的⽂件, ⽂件名就是模块的名字加上.py后缀. 换句话说我们⽬前写的所有的py⽂件都可以看成是⼀ ...

随机推荐

  1. [Javascript] Redirect the browser using JavaScript

    Three methods to preform redirection in browser: widnow.location.href window.location.assign window. ...

  2. bat处理文件

    bat处理文件 作用:可以一次性执行多个命令的文件. 为什么要学bat处理文件? 快速运行一个软件一般都会把软件打包一个jar包,但是jar双击可以运行仅对图形化界面的软件起作用,对于控制台的程序是不 ...

  3. javaweb 学习的好地方

    http://www.cnblogs.com/xdp-gacl/p/3729033.html 强烈推荐这个哥们的学习笔记.太赞了.

  4. get请求与post请求

    1. get是从服务器上获取数据,post是向服务器传送数据.2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过H ...

  5. 数据库分库分表(sharding)系列(三) 关于使用框架还是自主开发以及sharding实现层面的考量

    当团队对系统业务和数据库进行了细致的梳理,确定了切分方案后,接下来的问题就是如何去实现切分方案了,目前在sharding方面有不少的开源框架和产品可供参考,同时很多团队也会选择自主开发实现,而不管是选 ...

  6. 多种下载文件方式 Response.BinaryWrite(byte[] DocContent);Response.WriteFile(System.IO.FileInfo DownloadFile .FullName);Response.Write(string html2Excel);

    通过html给xls赋值,并下载xls文件 一.this.Response.Write(sw.ToString());System.IO.StringWriter sw = new System.IO ...

  7. 慕课linux学习笔记(六)常用命令(3)

    Find 命令 #搜索文件 Find [搜索范围] [搜索条件] e.g. find / -name isnstall.log 搜索速度会非常慢 避免大范围搜索,会非常耗费系统资源 Find是在系统当 ...

  8. Oracle11g R2学习系列 之五回闪

    Oracle里面有一个回闪的操作,这个貌似sql server是没有的.要使用这个功能,需要用到两个时间内部函数 TIMESTAMP和TO_TIMESTAMP.其中,函数TO_TIMESTAMP的语法 ...

  9. [转]shell中 source命令即点空格后面再跟可执行文件的说明

    这里记录的是在一个shell脚本里面使用. ./file.sh 和./file.sh 的区别,本文参考了http://www.lslnet.com/linux/dosc1/39/linux-28353 ...

  10. python保留两位小数

    python保留两位小数: In [1]: a = 5.026 In [2]: b = 5.000 In [3]: round(a,2) Out[3]: 5.03 In [4]: round(b,2) ...