Created
March 18, 2020 15:35
-
-
Save caiguanhao/4a81864970ad372fb4b55dbd5dcba382 to your computer and use it in GitHub Desktop.
net/ssh login with public key string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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