1

I'm going to place both my question and answer here, since I had a very difficult time figuring it out. (Also I started out trying to install the "ssh" library, but it has been superceded by the "paramiko" library of the same function. I may have missed a replacement here, please forgive if I have.)

Question: I need to install the "paramiko" library on a windows 7 system.

Pip and easy_install both give errors when trying to install the "Crypto" module.

I headed down a number of blind alleys involving Visual C and Visual Studio without success.

Answer:(in two parts) 1) Install the crypto library from a binary, like from here:

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

This installs the crypto library, but with a different capitalization than the paramiko library expects. So I learned a little trick over here: http://stackoverflow.com/questions/19623267/importerror-no-module-named-crypto-cipher with the answer by user "pho" to add these lines to the python program:

import crypto
import sys
sys.modules['Crypto'] = crypto

Now I am able to install, and run, the paramiko library. I hope this helps others find the solution more quickly.

Skip Huffman
  • 4,469
  • 8
  • 37
  • 49
  • A small note, you almost certainly want to be install `paramiko`, and not `ssh`. `ssh` was a fork of `paramiko` that is now merged upstream and unmaintained: https://pypi.python.org/pypi/ssh/1.8.0 – Alex Gaynor Jul 01 '14 at 17:03
  • Thank you. I intend to update after I get it all working properly for me. Including the paramiko change. Right now I am struggling with use of RSA keys. Once I get that taken care of I will improve this question and answer. ( I wanted to get at least the first part of this up right away so I wouldn't neglect it later and cost someone else all the time I spent on it.) – Skip Huffman Jul 01 '14 at 17:22

1 Answers1

2

Answer:(in two parts) 1) Install the crypto library from a binary, like from here:

http://www.voidspace.org.uk/python/modules.shtml#pycrypto note: the "paramiko" library has replaced "ssh" so this answer reflects that

This installs the crypto library, but with a different capitalization than the paramiko library expects. So I learned a little trick over here:

http://stackoverflow.com/questions/19623267/importerror-no-module-named-crypto-cipher

with the answer by user "pho" to add these lines to the python program:

import crypto
import sys
sys.modules['Crypto'] = crypto

Now I am able to install, and run, the paramiko library. I hope this helps others find the solution more quickly.

That was a good start. My next stopper was figuring out how to get the correct keys. If you are like me, you use putty and it's keygen utility for key management. And it works great! But it keeps it's private keys in a file different that what paramiko expects. But puttygen also provides a solution to this.

Open your *.ppk file in puttygen. To to Conversions->Export OpenSSH Key Save your private key as id_rsa (in .ssh directory, of course). (I am not sure the default name is required. Feel free to try something else and add a comment.)

Now paramiko will be able to automatically find it.

And here is my Resulting Script.

import sys
import crypto
sys.modules['Crypto'] = crypto
import paramiko

knownHosts  = 'C:/Users/Skip Huffman/.ssh/known_hosts'
keyFileName     = 'C:/Users/Skip Huffman/.ssh/id_rsa'
hostName    = "mcsremotetest1.cnn.vgtf.net"
userName    = "<username matching keypair>"

client = paramiko.SSHClient()
client.load_system_host_keys(knownHosts)
client.connect(hostName, username=userName)
stdin, stdout, stderr = client.exec_command('ls')
print "Standard Error: ", stderr.readlines()
print "Standard Output: ", stdout.readlines()

With a proper matching keypair this should now just work. It does for me. (substitute the proper username of course.)

Skip Huffman
  • 4,469
  • 8
  • 37
  • 49