python之paramiko模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之paramiko模块相关的知识,希望对你有一定的参考价值。

python paramiko模块

1.安装

1225 ./configure #在解压后的python2.7.9的目录下

1226 make

1227 make install

1228 cd /usr/local/

1229 ls

1230 cd bin

1231 ls

1232 ./python

1233 python

1234 cd /usr/bin

1235 ls

1236 ll python*

1237 mv ./python ./python26

1238 ln -s /usr/local/bin/python ./python #链接为2.7.9的版本

1239 ./python

1240 python

1241 pip

1242 cd /usr/local/

1243 cd lib

1244 ls

1245 cd python2.7/

1254 tar zxf pycrypto-2.6.1.tar.gz

1256 cd pycrypto-2.6.1

1258 python setup.py install

1259 python

>>> import Crypto

>>>

1263 tar xzf paramiko-2.0.2.tar.gz

1264 cd paramiko-2.0.2

1265 ls

1266 python setup.py install

import paramiko

Traceback (most recent call last):

File "setup.py", line 35, in <module>

from setuptools import setup

ImportError: No module named setuptools

1273 tar xzf setuptools-25.2.0.tar.gz

1274 cd setuptools-25.2.0

1275 ls

1276 python setup.py install

1277 ls

1278 cd ../paramiko-2.0.2

1279 ls

1280 python setup.py install

缺少gcc报错

yum intall -y gcc报错由于python升级导致

# vim /usr/bin/yum

#!/usr/bin/python2.6 #原本直接为python,改为未升级之前的版本

# yum install gcc libffi-devel python-devel openssl-devel

1281 python

import paramiko报错缺少模块

# wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz

# tar zxf 1.5.5

# cd pip-1.5.5/

# python setup.py install

# pip install paramiko报错

pkg_resources.DistributionNotFound: The ‘pip==7.1.0‘ distribution was not found and is required by the application

# easy_install pip==7.1.0

# pip install paramiko

1282 ls

1283 cd

1284 ls

1287 vim yzh.py

1288 python yzh.py

1289 vim yzh.py


2.python ssh模块登录

import paramiko

server_ip = ‘192.168.110.59‘

server_user = ‘root‘

server_passwd = ‘cyl&647308‘

server_port = 22

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #无密钥登录

ssh.connect(server_ip,username=server_user,password=server_passwd)

stdin, stdout, stderr = ssh.exec_command("/sbin/ifconfig")

#inf = stdout.readlines() #输出结果不分行

#print inf

for line in stdout:

print ‘...‘+line.strip(‘\n‘) #输出结果分行,按命令本身的显示输出

ssh.close()

print ‘close‘


本文出自 “真水无香” 博客,请务必保留此出处http://chengyanli.blog.51cto.com/11399167/1846787

以上是关于python之paramiko模块的主要内容,如果未能解决你的问题,请参考以下文章

Python模块之paramiko

python3之paramiko模块

python之paramiko模块

Python3之paramiko模块

python ssh之paramiko模块使用

Python远程连接主机之paramiko模块