Skip to content

Instantly share code, notes, and snippets.

@caiguanhao
Created March 18, 2020 15:35
Show Gist options
  • Save caiguanhao/4a81864970ad372fb4b55dbd5dcba382 to your computer and use it in GitHub Desktop.
Save caiguanhao/4a81864970ad372fb4b55dbd5dcba382 to your computer and use it in GitHub Desktop.
net/ssh login with public key string
host = 'host'
user = 'user'
options = {
keys_only: true,
keys: [],
key_data: [ server_ssh_private_key ],
user_known_hosts_file: [],
known_hosts: Class.new do
def self.search_for(host, options={})
fingerprint = server_ssh_fingerprint.split(/\s+/).last
key = Net::SSH::Buffer.new(fingerprint.unpack('m*').first).read_key
Net::SSH::HostKeys.new([ key ], host, nil, options)
end
end,
verify_host_key: :always,
}
Net::SSH.start(host, user, options) do |ssh|
end
Net::SFTP.start(host, user, options) do |sftp|
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment