Defined Type: ssh_keygen

Defined in:
manifests/init.pp

Overview

Examples:

Generate a dsa key

ssh_keygen { 'john':
  type => 'dsa'
}

specify the bit length

ssh_keygen { 'john':
  bits => 4096
}

Generate new host key

ssh_keygen { 'root':
  filename => '/etc/ssh/ssh_host_rsa_key'
}

Parameters:

  • user (Optional[String]) (defaults to: undef)

    Username to create key for

  • type (Enum['rsa', 'dsa', 'ecdsa', 'ed25519', 'rsa1']) (defaults to: 'rsa')

    Type of key to create

  • bits (Optional[Integer]) (defaults to: undef)

    Number of bits in key

  • home (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Home directory for user

  • filename (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Key filename

  • comment (Optional[String]) (defaults to: undef)

    Key comment

  • options (Optional[Array[String]]) (defaults to: undef)

    Additional options to pass on to ssh-keygen



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'manifests/init.pp', line 41

define ssh_keygen (
  Optional[String] $user     = undef,
  Enum['rsa', 'dsa', 'ecdsa', 'ed25519', 'rsa1'] $type   = 'rsa',
  Optional[Integer] $bits    = undef,
  Optional[Stdlib::Absolutepath] $home     = undef,
  Optional[Stdlib::Absolutepath] $filename = undef,
  Optional[String] $comment  = undef,
  Optional[Array[String]] $options  = undef,
) {
  Exec { path => '/bin:/usr/bin' }

  $_user = $user ? {
    undef   => $name,
    default => $user,
  }

  $_home = $home ? {
    undef   => $_user ? {
      'root'  => "/${_user}",
      default => "/home/${_user}",
    },
    default => $home,
  }

  $_filename = $filename ? {
    undef   => "${_home}/.ssh/id_${type}",
    default => $filename,
  }

  $type_opt = shell_join(['-t', $type])

  $bits_opt = $bits ? {
    undef   => undef,
    default => shell_join(['-b', $bits])
  }

  $filename_opt = shell_join(['-f', $_filename])
  $passphrase_opt = shell_join(['-N', ''])

  $comment_opt = $comment ? {
    undef   => undef,
    default => shell_join(['-C', $comment])
  }

  $options_opt = $options ? {
    undef   => undef,
    default => shell_join($options),
  }

  $command = delete_undef_values(
    [
      'ssh-keygen',
      $type_opt,
      $bits_opt,
      $filename_opt,
      $passphrase_opt,
      $comment_opt,
      $options_opt,
    ]
  )

  exec { "ssh_keygen-${name}":
    command => join($command, ' '),
    user    => $_user,
    creates => $_filename,
  }
}