Using paramiko rsa key

loial jldunn2000 at googlemail.com
Tue Feb 10 16:48:46 CET 2009


Can anyone be a little more helpful than Tino?

I have generated the key file as follows on windows and ftp'd the
id_rsa.pub file to the .ssh directory on the server and renamed to
authorized_keys


import paramiko


key = paramiko.RSAKey.generate(2048)

key.write_private_key_file('Z:/id_rsa')
file = open('Z:/id_rsa.pub','w')
file.write("ssh-rsa " +key.get_base64())
file.close()

But when I try to connect as follows I get an authentication failed
error.


import paramiko

paramiko.util.log_to_file('demo_sftp.log')

try:
    try:
        key = paramiko.RSAKey.from_private_key_file("Z:/id_rsa") #the
generated private key
    except Exception, e:
        print str(e)
    t = paramiko.Transport(('10.5.1.15', 22))
    print "here"
    t.start_client()
    t.auth_publickey('prod2',key)

    if t.is_authenticated():
        print "Got it!"
    sftp = paramiko.SFTPClient.from_transport(t)
    dirlist = sftp.listdir('.')
    print "Dirlist:", dirlist
    t.close()
except Exception, e:
    print str(e)
    t.close()






More information about the Python-list mailing list