I. Basic environment 1, role, IP, version, kernel servera 10.1.10.117 3.2.0-4-amd64 7.8 python pycrypto paramiko ecdsapython-2.7.3pycrypto-2.6.1paramiko-1.15.3pycrypto-2.6.1.tar.gzecdsa-0.13.tar.gzparamiko-1.15.3.tar.gz Second, Apt installs Paramiko1, installs the base package APT-GET -Y INSTALL GCC PYTHON-DEV PYTHON-SETUPTOOLS2, Install the PIP command easy_install pip3, query for installed packages 1) pip search "Pycrypto" pycrypto - cryptographic modules for python.2 ) pip search "Paramiko" paramiko - ssh2 protocol library4, install using PIP Mode 1) pip install pycryptocollecting pycrypto/usr/local/lib/python2.7/dist-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ ssl_.py:90: insecureplatformwarning: a true sslcontext object is not available. this Prevents urllib3 from configuring ssl appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. insecureplatformwarning downloading pycrypto-2.6.1.tar.gz (446kB) 100% |████████████████████████████████| 446kb 96kb/s installing collected packages: pycrypto running setup.py install for pycryptosuccessfully installed pycrypto-2.6.1/usr/local/lib/python2.7/dist-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/ Packages/urllib3/util/ssl_.py:90: insecureplatformwarning: a true sslcontext object is not available. this prevents urllib3 from configuring ssl appropriately and may cauSe certain ssl connections to fail. for more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. INSECUREPLATFORMWARNING2) pip install paramikocollecting paramiko/usr/local/lib/python2.7/ dist-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: insecureplatformwarning: a true sslcontext object is not available. this prevents urllib3 from configuring ssl appropriately and may Cause certain ssl connections to fail. for more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. insecureplatformwarning downloading paramiko-1.15.3-py2.py3-none-any.whl (166kB) 100% |████████████████████████████████| 167kb 104kb/s collecting ecdsa>=0.11 (From paramiko) Downloading ecdsa-0.13-py2.py3-none-any.whl (86kB) 100% | ████████████████████████████████| 90kb 165kb/s requirement already satisfied ( Use --upgrade to upgrade): pycrypto!=2.4,>=2.1 in /usr/local/lib/python2.7/ dist-packages (From paramiko) installing collected packages: ecdsa, paramikosuccessfully installed ecdsa-0.13 paramiko-1.15.3 Three, test
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/71/wKiom1Ydn_zzwLWJAADgZiDp0Uc129.jpg "title=" Aaa.png "alt=" wkiom1ydn_zzwlwjaadgzidp0uc129.jpg "/>
Four, the TAR package installs the PARAMIKO1, installs the basic package Apt-get -y install gcc python-dev2, the download pycryptowget -- no-check-certificate https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz#md5= 55a61a054aa66812daf5161a0d5d7eda3, unzip and enter the relevant directory TAR ZXVF PYCRYPTO-2.6.1.TAR.GZ && CD  PYCRYPTO-2.6.1 4, check the environment./CONFIGURE5, compile and install Python setup.py build && python setup.py install6, download ecdsawget --no-check-certificate https://pypi.python.org/packages/ source/e/ecdsa/ecdsa-0.13.tar.gz#md5=1f60eda9cb5c46722856db41a3ae66707, unzip and enter the relevant directory tar zxvf ecdsa-0.13.tar.gz && cd ecdsa-0.138, compile and install python setup.py build && python setup.py install9, download paramikowget --no-check-certificate https:// pypi.python.org/packages/source/p/paramiko/paramiko-1.15.3.tar.gz#md5=c959088669f8d951585aa6abc25c8ef610, Unzip and enter the relevant directory Tar zxvf paramiko-1.15.3.tar.gz && cd paramiko-1.15.311,
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/71/wKiom1YdoBmj0yevAAGXRqhE6Bw461.jpg "title=" Bbb.png "alt=" Wkiom1ydobmj0yevaagxrqhe6bw461.jpg "/>
12. Compile and install Python setup.py build && python setup.py install five, test
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/6D/wKioL1YdoEeSr9imAAD3_GV-09o128.jpg "title=" Ccc.png "alt=" Wkiol1ydoeesr9imaad3_gv-09o128.jpg "/>
Vi. using the Paramiko module (eg: multiple server queries) #!/usr/bin/python2.7# -*- coding: utf-8 -*-#-------------------- ------------------------------#Author: jimmygong#email:[email protected] #FileName:p aramiko.py#function: #Version:1.0 #Created: 2015-10-13#--------------------------------------------------import Reimport fileinputimport osimport sysimport paramikohost= "Host.txt" cmd= "Cmd.txt" if Os.path.isfile (host) and os.path.isfile (cmd): print "%s and %s exists,you can continue " % (host,cmd) else: print "%s or %s is lost,please check! " % (Host,cmd) sys.exit () port=22user= "root" password= "Redhat" i=0cmd1= "cat %s|grep ' 10.1 ' |wc -l " % hostnum1=os.popen (CMD1). read (). Strip () S=paramiko. Sshclient () S.load_system_host_keys () S.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) FOR&NBsp;line in fileinput.input (host,inplace=0): if re.search ("10.1", line): i+=1 host= Line.strip () t=paramiko. Transport ((Host,port)) t.connect (username=user,password= Password) s.connect (host,port,user,password,timeout=5) f=open (CMD) while true: cmd_line= F.readline () if len ( Cmd_line) == 0:break stdin,stdout,stderr=s.exec_command (Cmd_line) cmd_result=stdout.read (), Stderr.read () for result in cmd_ result: print "\033[32m %s \033[0m\n" % result, f.close () print "\x1b[0;33m %d/%d %s\x1b[0m" % (int (i), int (NUM1), line) m=i else: passprint "\033[32m allnum %d \033[0m\n" % int (m) print "#" *40s.close () PS: Related files cat cmd.txt crontab -lcat host.txt 10.1.10.18510.1.10.24 Seven, effect
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/71/wKiom1YdoDzQHYgrAAEfXHS7hnY530.jpg "title=" Ddd.png "alt=" Wkiom1ydodzqhygraaefxhs7hny530.jpg "/>
Viii. Reference Article https://pypi.python.org/pypi/pycryptohttps://pypi.python.org/pypi/paramikohttps://pypi.python.org/pypi/ Ecdsa/https://github.com/paramiko/paramiko/http://docs.paramiko.org/en/1.15/api/agent.html
This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1702704
Paramiko Installation and use