Module: CemAcpt::Utils::SSH
- Defined in:
- lib/cem_acpt/utils/ssh.rb
Overview
Defined Under Namespace
Modules: Ephemeral
Classes: Keygen
Class Method Summary
collapse
Class Method Details
.clean_ephemeral_keys ⇒ Object
.create(key_name, **options) ⇒ Object
117
118
119
120
121
|
# File 'lib/cem_acpt/utils/ssh.rb', line 117
def self.create(key_name, **options)
keygen = Keygen.new
keys = keygen.create(key_name, **options)
keys + ['/dev/null']
end
|
.create_known_hosts(known_hosts, overwrite: true, keydir: default_keydir) ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/cem_acpt/utils/ssh.rb', line 123
def self.create_known_hosts(known_hosts, overwrite: true, keydir: default_keydir)
return nil unless known_hosts
kh_file = file_path(known_hosts, keydir: keydir)
::File.open(kh_file, 'w') { |f| f.write("\n") } unless ::File.exist?(kh_file) && !overwrite
kh_file
end
|
.default_keydir ⇒ Object
98
99
100
101
102
103
|
# File 'lib/cem_acpt/utils/ssh.rb', line 98
def self.default_keydir
ssh_dir = ::File.join(ENV['HOME'], '.ssh')
raise "SSH directory at #{ssh_dir} does not exist" unless ::File.directory?(ssh_dir)
ssh_dir
end
|
.ephemeral_ssh_key(keydir: default_keydir) ⇒ Object
135
136
137
|
# File 'lib/cem_acpt/utils/ssh.rb', line 135
def self.ephemeral_ssh_key(keydir: default_keydir)
CemAcpt::Utils::SSH::Ephemeral.create(keydir: keydir)
end
|
.file_path(file_name, keydir: default_keydir) ⇒ Object
105
106
107
|
# File 'lib/cem_acpt/utils/ssh.rb', line 105
def self.file_path(file_name, keydir: default_keydir)
::File.join(keydir, file_name)
end
|
.key_paths(file_name, keydir: default_keydir) ⇒ Object
Takes a file name (not path) and optional SSH key directory and returns the paths to the private key and public key based on the file name given.
113
114
115
|
# File 'lib/cem_acpt/utils/ssh.rb', line 113
def self.key_paths(file_name, keydir: default_keydir)
[file_path(file_name, keydir: keydir), file_path("#{file_name}.pub", keydir: keydir)]
end
|
.set_ssh_file_permissions(*files) ⇒ Object
131
132
133
|
# File 'lib/cem_acpt/utils/ssh.rb', line 131
def self.set_ssh_file_permissions(*files)
files.uniq.compact.map { |p| ::File.chmod(0o600, p) }
end
|
.ssh_keygen ⇒ Object
91
92
93
94
95
96
|
# File 'lib/cem_acpt/utils/ssh.rb', line 91
def self.ssh_keygen
bin_path = CemAcpt::Utils::Shell.which('ssh-keygen')
raise 'Cannot find command ssh-keygen in PATH, make sure it is installed' if bin_path.nil?
bin_path
end
|