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
运行代码后,它仍然问我密码。
admin@roku.staging.com的密码:
请帮忙解决这个问题
答案 0 :(得分:0)
尝试使用此功能,我认为您的参数不正常,请尝试只填充此键的字符串
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
和配置,私钥的路径应该是绝对路径,
还尝试/验证您的私人rsa文件:
$ sftp -i .ssh / ssh-2-rsa user@sftp.ip.net