Class: RediPress::SSHKeys

Inherits:
Object
  • Object
show all
Defined in:
lib/redipress/ssh.rb

Overview

This class contains stuff related to SSH Keys

Class Method Summary collapse

Class Method Details

.load_ssh_keysObject

Load all SSH Keys stored in the user’s SSH directory

Example:

>> RediPress::SSHKeys.load_ssh_keys
=> nil


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/redipress/ssh.rb', line 15

def self.load_ssh_keys
  # Get the path to the user's personal SSH directory
  ssh_directory = File.join(Dir.home, ".ssh")

  # Return unless the SSH directory exists
  return nil unless File.directory?(ssh_directory)

  # Get the paths of all SSH Keys
  ssh_keys = Dir.glob(File.join(Dir.home, ".ssh", "*.pub")).map do |key|
  	File.join(File.dirname(key), File.basename(key, ".pub"))
  end

  # Adjust the configuration options for SSH Kit
  SSHKit::Backend::Netssh.configure do |ssh|
  	# Set the SSH options
  	ssh.ssh_options = {
  		# Set the SSH Keys to use when attempting to login to the remote host
  		keys: ssh_keys,

  		# Set the authentication methods
  		auth_methods: %w(publickey)
  	}
  end

  nil
end