Installing the Python SSH module under windows and using __python

Source: Internet
Author: User
There is no dedicated SSH module in Python, which requires a manual installation module. The use of SSH in Python requires openssh, while OpenSSH relies on Paramiko modules, and Paramiko modules rely on Pycrypto modules, so to use SSH in Python, the order of the modules to be installed is pycrypto-〉 Paramiko. Install OpenSSHOpenSSH Download URL: http://sourceforge.net/projects/sshwindows/, download installation can be.
Installing the Pycrypto module

Pycrypto module Download Address: http://pypi.python.org/pypi/pycrypto/, download installation when the lack of vcvarsall.bat, prompted the need for Visual Studio, online solutions are mostly installed MingW32.

Find the Pycrypto version used in the compiled windows on the Internet, download the URL:

Http://www.voidspace.org.uk/python/modules.shtml#pycrypto

Download the Python version and the corresponding version of the operating system, install it directly.

Note: If it is Win32bit + Python 2.7, download Pycrypto-2.6.win32-py2.7.exe. Installing the Paramiko module

Download the latest version of the Paramiko module from the Http://pypi.python.org/pypi/paramiko URL, unzip it, and go to the uncompressed directory to perform the Python setup.py install installation. using the sample

Use SSH to log on to a remote host to execute commands.

Import Paramiko

def ssh_cmd (ip,port, cmd, User, passwd):

result = ""

Try

SSH = Paramiko. Sshclient ()

Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

Ssh.connect (IP, port, user, passwd,timeout=3)

stdin, stdout, stderr =ssh.exec_command (CMD)

result = Stdout.read ()

Ssh.close ()

Except

Print ("Ssh_cmd err.")

return result

Related Article

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.