Using paramiko rsa key

Discussion in 'Python' started by loial, Feb 10, 2009.

  1. loial

    loial Guest

    I want to connect via ssh from a python script on windows to an AIX
    server running openSSH using rsa keys rather than a password.

    Can anyone provide me with /point me at a simple tutuorial on the
    steps I need to go though in terms of geneerating the key, installing
    on the server and connecting in my python code?

    Thanks in advance.
     
    loial, Feb 10, 2009
    #1
    1. Advertising

  2. loial

    loial Guest

    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()
     
    loial, Feb 10, 2009
    #2
    1. Advertising

  3. loial wrote:
    > Can anyone be a little more helpful than Tino?

    <cut>
    I'll do some freebie hints :)
    What I would do is try first whether key authentication works at all,
    for example following a tutorial like
    http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html

    And if that works translate it to the relevant python code.

    --
    mph
     
    Martin P. Hellwig, Feb 10, 2009
    #3
  4. loial

    loial Guest

    On 10 Feb, 17:08, "Martin P. Hellwig" <>
    wrote:
    > loial wrote:
    > > Can anyone be a little more helpful than Tino?

    >
    > <cut>
    > I'll do some freebie hints :)
    > What I would do is try first whether key authentication works at all,
    > for example following a tutorial likehttp://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html
    >
    > And if that works translate it to the relevant python code.
    >
    > --
    > mph


    Thanks..I'll try that first
     
    loial, Feb 10, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Bergstrom
    Replies:
    0
    Views:
    1,227
    John Bergstrom
    Aug 3, 2003
  2. gg
    Replies:
    0
    Views:
    2,709
  3. Replies:
    0
    Views:
    6,056
  4. k2
    Replies:
    0
    Views:
    220
  5. John Bergstrom
    Replies:
    0
    Views:
    102
    John Bergstrom
    Aug 3, 2003
Loading...

Share This Page