Class: Net::SSH::Authentication::KeyManager

Class | Net::SSH::Authentication::KeyManager
In: | lib/net/ssh/authentication/key_manager.rb
Parent: | Object

This class encapsulates all operations done by clients on a user‘s private keys. In practice, the client should never need a reference to a private key; instead, they grab a list of "identities" (public keys) that are available from the KeyManager, and then use the KeyManager to do various private key operations using those identities.

The KeyManager also uses the Agent class to encapsulate the ssh-agent. Thus, from a client‘s perspective it is completely hidden whether an identity comes from the ssh-agent or from a file on disk.

### Methods

add add_key_data agent clear! each_identity finish new sign use_agent= use_agent?

### Included Modules

Loggable

### Attributes

key_data | [R] | The list of user key data that will be examined
key_files | [R] | The list of user key files that will be examined
known_identities | [R] | The map of loaded identities
options | [R] | The map of options that were passed to the key-manager

### Public Class methods

new(logger, options={})

Create a new KeyManager. By default, the manager will use the ssh-agent (if it is running).

### Public Instance methods

add(key_file)

Add the given key_file to the list of key files that will be used.

add_key_data(key_data_)

Add the given key_file to the list of keys that will be used.

agent()

Returns an Agent instance to use for communicating with an SSH agent process. Returns nil if use of an SSH agent has been disabled, or if the agent is otherwise not available.

clear!()

Clear all knowledge of any loaded user keys. This also clears the list of default identity files that are to be loaded, thus making it appropriate to use if a client wishes to NOT use the default identity files.

each_identity() {|key| ...}

Iterates over all available identities (public keys) known to this manager. As it finds one, it will then yield it to the caller. The origin of the identities may be from files on disk or from an ssh-agent. Note that identities from an ssh-agent are always listed first in the array, with other identities coming after.

finish()

This is used as a hint to the KeyManager indicating that the agent connection is no longer needed. Any other open resources may be closed at this time.

Calling this does NOT indicate that the KeyManager will no longer be used. Identities may still be requested and operations done on loaded identities, in which case, the agent will be automatically reconnected. This method simply allows the client connection to be closed when it will not be used in the immediate future.

sign(identity, data)

Sign the given data, using the corresponding private key of the given identity. If the identity was originally obtained from an ssh-agent, then the ssh-agent will be used to sign the data, otherwise the private key for the identity will be loaded from disk (if it hasn‘t been loaded already) and will then be used to sign the data.

Regardless of the identity‘s origin or who does the signing, this will always return the signature in an SSH2-specified "signature blob" format.

use_agent=(use_agent)

Toggles whether the ssh-agent will be used or not. If true, an attempt will be made to use the ssh-agent. If false, any existing connection to an agent is closed and the agent will not be used.

use_agent?()

Identifies whether the ssh-agent will be used or not.

[Validate]