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: