Installing the python SSH module in windows and Its Usage

Source: Internet
Author: User

 There is no dedicated SSH module in Python, which requires manual installation of the module. OpenSSH is required to use SSH in Python. OpenSSH depends on the paramiko module and the paramiko module depends on the pycrypto module. Therefore, ssh must be used in Python, the module installation sequence is pycrypto-> paramiko.

Install OpenSSH

OpenSSH download URL: http://sourceforge.net/projects/sshwindows/, download and install now. Install the pycrypto Module

Pycrypto module: Cipher.

Find the compiled version of pycrypto in windows on the Internet. The download URL is:

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

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

NOTE: If it is win32bit + Python 2.7,, pycrypto-2.6.win32-py2.7.exe will be downloaded.

Install the paramiko Module

Install it from composer setup. py install.

Example

Log on to the remote host using SSH 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 implements ssh.exe c_command (CMD)

Result = stdout. Read ()

Ssh. Close ()

Except t:

Print ("ssh_cmd err .")

Return result

Share:
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.