Exception: Net::SSH::HostKeyError

Inherits:
Exception
  • Object
show all
Defined in:
lib/net/ssh/errors.rb

Overview

Base class for host key exceptions. When rescuing this exception, you can inspect the key fingerprint and, if you want to proceed anyway, simply call the remember_host! method on the exception, and then retry.

Direct Known Subclasses

HostKeyMismatch, HostKeyUnknown

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callback=(value) ⇒ Object (writeonly)

the callback to use when #remember_host! is called



48
49
50
# File 'lib/net/ssh/errors.rb', line 48

def callback=(value)
  @callback = value
end

#data=(value) ⇒ Object (writeonly)

situation-specific data describing the host (see #host, #port, etc.)



51
52
53
# File 'lib/net/ssh/errors.rb', line 51

def data=(value)
  @data = value
end

Instance Method Details

#[](key) ⇒ Object

An accessor for getting at the data that was used to look up the host (see also #fingerprint, #host, #port, #ip, and #key).



55
56
57
# File 'lib/net/ssh/errors.rb', line 55

def [](key)
  @data && @data[key]
end

#fingerprintObject

Returns the fingerprint of the key for the host, which either was not found or did not match.



61
62
63
# File 'lib/net/ssh/errors.rb', line 61

def fingerprint
  @data && @data[:fingerprint]
end

#hostObject

Returns the host name for the remote host, as reported by the socket.



66
67
68
# File 'lib/net/ssh/errors.rb', line 66

def host
  @data && @data[:peer] && @data[:peer][:host]
end

#ipObject

Returns the IP address of the remote host, as reported by the socket.



76
77
78
# File 'lib/net/ssh/errors.rb', line 76

def ip
  @data && @data[:peer] && @data[:peer][:ip]
end

#keyObject

Returns the key itself, as reported by the remote host.



81
82
83
# File 'lib/net/ssh/errors.rb', line 81

def key
  @data && @data[:key]
end

#portObject

Returns the port number for the remote host, as reported by the socket.



71
72
73
# File 'lib/net/ssh/errors.rb', line 71

def port
  @data && @data[:peer] && @data[:peer][:port]
end

#remember_host!Object

Tell Net::SSH to record this host and key in the known hosts file, so that subsequent connections will remember them.



87
88
89
# File 'lib/net/ssh/errors.rb', line 87

def remember_host!
  @callback.call
end