Class: GDKBox::SSHKey
- Inherits:
-
Object
- Object
- GDKBox::SSHKey
- Defined in:
- lib/gdkbox/ssh_key.rb
Overview
Manages a dedicated ed25519 keypair used to authenticate into boxes.
gdkbox keeps its own key under the gdkbox home rather than touching the user's personal keys. The public half is installed into each box; the private half is referenced from the generated SSH config.
Instance Method Summary collapse
-
#ensure! ⇒ Object
Generate the keypair if it does not yet exist, returning the public key.
-
#initialize(config:, shell: Shell.new) ⇒ SSHKey
constructor
A new instance of SSHKey.
- #public_key ⇒ Object
Constructor Details
Instance Method Details
#ensure! ⇒ Object
Generate the keypair if it does not yet exist, returning the public key.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gdkbox/ssh_key.rb', line 16 def ensure! return public_key if File.exist?(@config.public_key_path) @config.ensure_dirs! unless @shell.which("ssh-keygen") raise Error, "ssh-keygen not found on PATH; cannot generate an SSH key" end @shell.run!( "ssh-keygen", "-t", "ed25519", "-N", "", "-C", "gdkbox", "-f", @config.private_key_path ) public_key end |
#public_key ⇒ Object
32 33 34 |
# File 'lib/gdkbox/ssh_key.rb', line 32 def public_key File.read(@config.public_key_path).strip end |