Class: SSHKit::EC2InstanceConnect::SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/ec2instanceconnect/ssh_key.rb

Overview

Generate a private/public SSH keypair.

Instance Method Summary collapse

Constructor Details

#initialize(size:) ⇒ SSHKey

Returns a new instance of SSHKey.



10
11
12
# File 'lib/sshkit/ec2instanceconnect/ssh_key.rb', line 10

def initialize(size:)
  @key = OpenSSL::PKey::RSA.generate(size)
end

Instance Method Details

#private_keyObject



14
15
16
# File 'lib/sshkit/ec2instanceconnect/ssh_key.rb', line 14

def private_key
  @key.to_pem
end

#public_keyObject



18
19
20
21
22
23
# File 'lib/sshkit/ec2instanceconnect/ssh_key.rb', line 18

def public_key
  blob = @key.public_key.to_blob
  encoded = [blob].pack('m0')

  "ssh-rsa #{encoded}"
end