0

I am trying to establish a sftp connection to my azure storage. I have a private key file which starts with

private_key = '-----BEGIN RSA PRIVATE KEY-----\nMnx......'

With this private_key, I try to establish the connection like

Net::SFTP.start('<remote-ip>', 'username', 
        :password => 'password', 
        :key_data => [ private_key ],
        keys_only: true,
        verify_host_key: :never) do |sftp|
          data = sftp.download!("/somefile.txt")
          p data

end

When I try to use this key file, I am getting an exception like

#<OpenSSL::PKey::PKeyError: Could not parse PKey: no start line>

However when I was using a key file which starts with below format

-----BEGIN OPENSSH PRIVATE KEY-----

everything was working fine.

But I want to use the new private key. What will be wrong in this code? Is there a way to specify the type of private key file to be used?

deepak asai
  • 202
  • 1
  • 5
  • 17

1 Answers1

0

do this:

Before this action call, check if private_key variable contains -----BEGIN OPENSSH PRIVATE KEY----- line. If not, then prepend this to the private_key variable or in short bring private_key to the format which your start method is accepting.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
ARK
  • 772
  • 7
  • 21