Install the paramiko module on Windows and Linux

Source: Internet
Author: User

1. What is the use of the paramiko module?

Paramiko is a module written in python. It complies with the SSH2 protocol and supports remote server connection through encryption and authentication. Because python is a language that can run across platforms, all platforms supported by python, such as Linux, Solaris, BSD, MacOS X, and Windows, and paramiko are supported. Therefore, paramiko is one of the best tools to connect to another platform using SSH for a series of operations, such as executing commands in batches and uploading files in batches.

The current new version is available on the official website:

Https://github.com/paramiko/paramiko

The old version is here:

Http://www.lag.net/paramiko/legacy.html


To install the new paramiko module, make the following preparations:


1. Python2.5 + version Linux, Unix, and Windows). Install Python2.7 directly.
: Http://www.python.org


2. PyCrypto 2.1 + module PyCrypto is an encryption toolkit written in Python)
: Https://www.dlitz.net/software/pycrypto/


3. The easy_install tool is a tool used to install Python modules. For example, yum can automatically resolve dependencies)

: Http://peak.telecommunity.com/dist/ez_setup.py


If you feel it is a little troublesome to install paramiko, it is worthwhile to use the convenience provided by paramiko.


Ii. Install paramiko on Linux using CentOS 5.8 32-bit as an example)


1. Check whether the Python version meets the requirements.


[root@server1 ~]# python -VPython 2.4.3[root@server1 ~]#

This command is also used on Windows. Note that it is an uppercase V

Version 2.4.3. Upgrade required


2. Download and install python2.7


Install Python with source code
If no gcc is installed, install gcc first.

root@server2 ~]# wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2[root@server2 ~]# tar jxf Python-2.7.5.tar.bz2[root@server2 ~]# cd Python-2.7.5[root@server2 Python-2.7.5]# ./configure --prefix=/usr/local/python2.7[root@server2 Python-2.7.5]# make && make install[root@server2 Python-2.7.5]# echo "PATH=/usr/local/python2.7/bin:$PATH" >> /etc/profile[root@server2 Python-2.7.5]# source /etc/profile[root@server2 Python-2.7.5]# python -VPython 2.7.5[root@server2 Python-2.7.5]# pythonPython 2.7.5 (default, Aug 16 2013, 07:56:41)[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>


So far, Python2.7 has been installed successfully.


3. Install the easy_install Tool


Download this script

[root@server2 ~]# wget http://peak.telecommunity.com/dist/ez_setup.py[root@server2 ~]# python ez_setup.pyDownloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.eggProcessing setuptools-0.6c11-py2.7.eggCopying setuptools-0.6c11-py2.7.egg to /usr/local/python2.7/lib/python2.7/site-packagesAdding setuptools 0.6c11 to easy-install.pth fileInstalling easy_install script to /usr/local/python2.7/binInstalling easy_install-2.7 script to /usr/local/python2.7/binInstalled /usr/local/python2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.eggProcessing dependencies for setuptools==0.6c11Finished processing dependencies for setuptools==0.6c11

Run the preceding command to install the easy_install tool.


4. Install the paramiko Module


Run the following command to install the paramiko module.

[root@server2 ~]# easy_install paramiko


Go to Python and import paramiko.

[root@server2 ~]# pythonPython 2.7.5 (default, Aug 16 2013, 07:56:41)[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import paramiko/usr/local/python2.7/lib/python2.7/site-packages/pycrypto-2.6-py2.7-linux-i686.egg/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.>>>


When importing a module, if you encounter the above problems, it may be caused by a relatively low gmp version. What is gmp? Please refer to the explanation on the official website:
GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers.
It seems to be related to precision.

You can solve this problem by using the following methods:
Uninstall earlier versions

root@server2 ~]# rpm -qa | grep gmpgmp-devel-4.1.4-10.el5gmp-4.1.4-10.el5[root@server2 ~]# rpm -e gmp-devel-4.1.4-10.el5.i386[root@server2 ~]# rpm -e gcc-gfortran-4.1.2-52.el5.i386[root@server2 ~]# rpm -e gmp-4.1.4-10.el5[root@server2 ~]# ldconfig[root@server2 ~]#


Then install the higher version of gmp


[root@server2 ~]# wget http://ftp.gnu.org/gnu/gmp/gmp-5.1.2.tar.bz2[root@server2 ~]# tar jxf gmp-5.1.2.tar.bz2[root@server2 ~]# cd gmp-5.1.2[root@server2 gmp-5.1.2]# ./configure && make && make install[root@server2 gmp-5.1.2]# echo "/usr/local/lib" >> /etc/ld.so.conf[root@server2 gmp-5.1.2]# ldconfig


Try to import the paramiko module again:


[root@server2 gmp-5.1.2]# pythonPython 2.7.5 (default, Aug 16 2013, 07:56:41)[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import paramiko>>> dir(paramiko)['AUTH_FAILED', 'AUTH_PARTIALLY_SUCCESSFUL', 'AUTH_SUCCESSFUL', 'Agent', 'AgentKey', 'AuthHandler', 'AuthenticationException', 'AutoAddPolicy', 'BadAuthenticationType', 'BadHostKeyException', 'BaseSFTP', 'BufferedFile', 'Channel', 'ChannelException', 'ChannelFile', 'DSSKey', 'HostKeys', 'InteractiveQuery', 'Message', 'MissingHostKeyPolicy', 'OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED', 'OPEN_FAILED_CONNECT_FAILED', 'OPEN_FAILED_RESOURCE_SHORTAGE', 'OPEN_FAILED_UNKNOWN_CHANNEL_TYPE', 'OPEN_SUCCEEDED', 'PKey', 'Packetizer', 'PasswordRequiredException', 'ProxyCommand', 'ProxyCommandFailure', 'RSAKey', 'RejectPolicy', 'SFTP', 'SFTPAttributes', 'SFTPClient', 'SFTPError', 'SFTPFile', 'SFTPHandle', 'SFTPServer', 'SFTPServerInterface', 'SFTP_BAD_MESSAGE', 'SFTP_CONNECTION_LOST', 'SFTP_EOF', 'SFTP_FAILURE', 'SFTP_NO_CONNECTION', 'SFTP_NO_SUCH_FILE', 'SFTP_OK', 'SFTP_OP_UNSUPPORTED', 'SFTP_PERMISSION_DENIED', 'SSHClient', 'SSHConfig', 'SSHException', 'SecurityOptions', 'ServerInterface', 'SubsystemHandler', 'Transport', 'WarningPolicy', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__version__', 'agent', 'auth_handler', 'ber', 'buffered_pipe', 'channel', 'client', 'common', 'compress', 'config', 'dsskey', 'file', 'hostkeys', 'io_sleep', 'kex_gex', 'kex_group1', 'message', 'packet', 'pipe', 'pkey', 'primes', 'proxy', 'resource', 'rsakey', 'server', 'sftp', 'sftp_attr', 'sftp_client', 'sftp_file', 'sftp_handle', 'sftp_server', 'sftp_si', 'ssh_exception', 'sys', 'transport', 'util']>>>


Everything is normal. Now the paramiko module has been installed on Linux.


5. If manual installation is troublesome, please use the following one-click installation script to download the attachment)

Run the script using the <source Script Name> method.


#! /Bin/bash # features # Name: one_key_install_paramiko # Purpose: one-click installation of paramiko environment # Version: 1.0 # Author: LEO # BLOG: http://linux5588.blog.51cto.com # EMAIL: chanyipiaomiao@163.com # Created: 2013-09-06 # Copyright: (c) LEO 2013 # ------------------------------------------------- export PATH =/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin: /usr/local/bin:/sbin: /Bin:/usr/sbin:/usr/bin:/root/bin # Check whether GCC has checkGCC () {if! Gcc-v &>/dev/null; then echo "GCC not Found! Please use <yum-y install gcc *> "echo exit 1 fi} # install new version gmp package installNewGMP () {wget http://ftp.gnu.org/gnu/gmp/gmp-5.1.2.tar.bz2 tar jxf gmp-5.1.2.tar.bz2 cd gmp-5.1.2. /configure & make install echo "/usr/local/lib">/etc/ld. so. conf ldconfig} # Install the easy_install tool installEasy_install () {if easy_install-h &>/dev/null; then echo "easy_install already installed" echo else wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py fi} # Install paramiko module installParamiko () {easy_install paramiko} # Install Python2.7installPython27 () {wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2 tar jxf Python-2.7.5.tar.bz2 cd Python-2.7.5. /configure -- prefix =/usr/local/python2.7 make & make install echo "export PATH =/usr/local/python2.7/bin: $ PATH ">/etc/profile source/etc/profile} # Check whether the Python version meets the requirements TEMP =" tempfile "checkPython () {python-V 2 >$ {TEMP} VERSION = $ (awk-F. '{print $2}' $ {TEMP}) rm-f $ {TEMP} if [[$ VERSION-lt 7]; then echo "Python Version does not meet the requirements, We Will auto download and install. "echo installPython27 installEasy_install installParamiko else installEasy_install installParamiko fi} # Call Function check GCCcheckGCC # Call function install new version gmpinstallNewGMP # Call Function check PythoncheckPython


Iii. Install the paramiko module on Windows 7 32


1. Download and install python2.7


Download these two files with the download Tool
Http://www.python.org/ftp/python/2.7.5/python-2.7.5.msi
Http://peak.telecommunity.com/dist/ez_setup.py
The default installation path is C: \ Python27.

After installation, add C: \ Python27 to the Path variable of the system, and then enter python in the command line to test.

C:\Users\TestAA>pythonPython 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>

The above result indicates that python has been installed successfully.


2. Install the easy_install Tool


C:\Users\TestAA\Desktop>python ez_setup.pyDownloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.eggProcessing setuptools-0.6c11-py2.7.eggCopying setuptools-0.6c11-py2.7.egg to c:\python27\lib\site-packagesAdding setuptools 0.6c11 to easy-install.pth fileInstalling easy_install-script.py script to C:\Python27\ScriptsInstalling easy_install.exe script to C:\Python27\ScriptsInstalling easy_install.exe.manifest script to C:\Python27\ScriptsInstalling easy_install-2.7-script.py script to C:\Python27\ScriptsInstalling easy_install-2.7.exe script to C:\Python27\ScriptsInstalling easy_install-2.7.exe.manifest script to C:\Python27\ScriptsInstalled c:\python27\lib\site-packages\setuptools-0.6c11-py2.7.eggProcessing dependencies for setuptools==0.6c11Finished processing dependencies for setuptools==0.6c11


Then add the Path C: \ Python27 \ Scripts to the Path variable of the system, so that you can directly use the easy_install command.


3. Install the PyCrypto Module


On the Windows platform, whether you use manual compilation or the easy_install command to install the module
It is prone to problems and especially troublesome, so someone has helped us compile the corresponding version on Windows platform, just download and install it.

Download the corresponding version pycrypto-2.6.win32-py2.7 to this location
Http://www.voidspace.org.uk/python/modules.shtml#pycrypto

Or download it to my online storage.
Http://pan.baidu.com/share/link? Consumer id = 3896105660 & uk = 839171987

The installation process only requires the next step.


4. Install the paramiko module using easy_install


C:\Users\TestAA>easy_install paramikoSearching for paramikoReading http://pypi.python.org/simple/paramiko/Best match: paramiko 1.11.0Downloading https://pypi.python.org/packages/source/p/paramiko/paramiko-1.11.0.tar.gz#md5=a2c55dc04904bd08d984533703177084Processing paramiko-1.11.0.tar.gzRunning paramiko-1.11.0\setup.py -q bdist_egg --dist-dir c:\users\testaa\appdata\local\temp\easy_install-rla6aa\paramiko-1.11.0\egg-dist-tmp-aynqgvzip_safe flag not set; analyzing archive contents...Adding paramiko 1.11.0 to easy-install.pth fileInstalled c:\python27\lib\site-packages\paramiko-1.11.0-py2.7.eggProcessing dependencies for paramikoFinished processing dependencies for paramikoC:\Users\TestAA>


Go to Python and import paramiko,


C:\Users\TestAA>pythonPython 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import paramiko>>> dir(paramiko)['AUTH_FAILED', 'AUTH_PARTIALLY_SUCCESSFUL', 'AUTH_SUCCESSFUL', 'Agent', 'AgentKey', 'AuthHandler', 'AuthenticationException', 'AutoAddPolicy', 'BadAuthenticationType', 'BadHostKeyException', 'BaseSFTP', 'BufferedFile', 'Channel', 'ChannelException', 'ChannelFile', 'DSSKey', 'HostKeys', 'InteractiveQuery', 'Message', 'MissingHostKeyPolicy', 'OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED', 'OPEN_FAILED_CONNECT_FAILED', 'OPEN_FAILED_RESOURCE_SHORTAGE', 'OPEN_FAILED_UNKNOWN_CHANNEL_TYPE', 'OPEN_SUCCEEDED', 'PKey', 'Packetizer', 'PasswordRequiredException', 'ProxyCommand', 'ProxyCommandFailure', 'RSAKey', 'RejectPolicy', 'SFTP', 'SFTPAttributes', 'SFTPClient', 'SFTPError', 'SFTPFile', 'SFTPHandle', 'SFTPServer', 'SFTPServerInterface', 'SFTP_BAD_MESSAGE', 'SFTP_CONNECTION_LOST', 'SFTP_EOF', 'SFTP_FAILURE', 'SFTP_NO_CONNECTION', 'SFTP_NO_SUCH_FILE', 'SFTP_OK', 'SFTP_OP_UNSUPPORTED', 'SFTP_PERMISSION_DENIED', 'SSHClient', 'SSHConfig', 'SSHException', 'SecurityOptions', 'ServerInterface', 'SubsystemHandler', 'Transport', 'WarningPolicy','__all__', '__author__', '__builtins__', '__doc__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__version__', 'agent', 'auth_handler', 'ber', 'buffered_pipe', 'channel', 'client', 'common', 'compress', 'config', 'dsskey', 'file', 'hostkeys', 'io_sleep', 'kex_gex', 'kex_group1', 'message', 'packet', 'pipe', 'pkey', 'primes', 'proxy', 'resource', 'rsakey', 'server', 'sftp', 'sftp_attr', 'sftp_client', 'sftp_file', 'sftp_handle', 'sftp_server', 'sftp_si', 'ssh_exception', 'sys', 'transport', 'util']>>>


As shown in the preceding figure, paramiko has been successfully installed.

This article is from the blog of reelcos, please be sure to keep this source http://linux5588.blog.51cto.com/65280/1275180

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.