Module: SSHKeyGenerator

Extended by:
SSHKeyGenerator
Included in:
SSHKeyGenerator
Defined in:
lib/sshkg/version.rb,
lib/sshkg/generator.rb

Defined Under Namespace

Modules: Version

Constant Summary collapse

DEFAULT_TYPE =
:dsa
DEFAULT_BITS =
1024
DEFAULT_COMMENT =
"example.com"

Instance Method Summary collapse

Instance Method Details

#generate(atts = { }) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sshkg/generator.rb', line 12

def generate( atts = { } )

  raise ArgumentError.new( "There is an argument problem" ) if atts.empty?
  raise ArgumentError.new( "You need an user id" ) unless atts[:user]
  
  user    = atts[:user]
  type    = atts[:type] ? atts[:type] : DEFAULT_TYPE    
  bits    = atts[:bits] ? atts[:bits] : DEFAULT_BITS
  comment = atts[:comment] ? atts[:comment] : DEFAULT_COMMENT

  %x{ssh-keygen -q -b #{bits} -t #{type} -f id_#{type}.#{user} -C #{user}@#{comment} 2>/dev/null </dev/null}
end