0
require 'net/ssh'
require 'net/sftp'

SREVER = "roku.staging.com" # Server name
KEYFILE = "path_to_privat/id_rsa" # Path to private key

Net::SFTP.start(SREVER, 'admin', :keys=>[KEYFILE]) do |sftp|
  sftp.mkdir! "/myfolder/test"
  puts "Connected to SFTP server"
end

After ran the code it still ask me password.

admin@roku.staging.com's password:

Could you please help to resolve this

Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
Chinya
  • 419
  • 1
  • 7
  • 18

1 Answers1

0

Try to with this function, I think that your parameters are not ok, try fullfilling this key only a string

  def self.upload_xml(file)
    Net::SFTP.start(
      "ip",
      "user",
      #password: "password", is a comment
      key_data: [],
      keys: "/private/key/path/rsa_file",
      keys_only: true,
      verify_host_key: false
    ) do |sftp|
      # do your things for example upload a file
      sftp.upload!(file.document.path,
                   file.document.original_filename)
    end
  end

and the configuration, the path to your private key should be and absolute path,

also try/verify your private rsa file:

$sftp -i .ssh/ssh-2-rsa user@sftp.ip.net

anquegi
  • 11,125
  • 4
  • 51
  • 67