Miss any of our Open RFC calls?Watch the recordings here! »

ssh-keygen2

0.1.0 • Public • Published

ssh-keygen2

Automate ssh-keygen command for generating RSA keypairs

Rationale

This module is useful if you want:

  • encrypted PEM format (keypair and rsa-json do not support this)
  • ssh-format, single-line pubkey (again not supported by the above modules)
  • fingerprint (supported by ssh-keygen but requires a second function call)
  • error handling (errors are not handled by ssh-keygen)
  • option to keep the resulting key files, or clean them up (ssh-keygen's destroy option does nothing)
  • randomart.

Requirements

This is just a wrapper around ssh-keygen, so it requires that command to be installed and in the path.

Usage

var keygen = require('ssh-keygen2')
  , assert = require('assert')
 
// generate a temporary keypair and return details
keygen(function (err, keypair) {
  assert.ifError(err);
  console.log(keypair.private);
  console.log(keypair.public);
  console.log(keypair.fingerprint + '\n');
  console.log(keypair.randomart + '\n');
});

This outputs:

-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA0Y79xltKAFobrBe/uIyDoZJGsd946jsiFBNXUp5Lp9JPbP/+
2K/E09exEOXdVIaZTLM/jS3rYV+tx/7KS8c6DItl3xksm/RWIUdrfq+quq2py4k2
K3AIMarZj9RZaANCWlgDvAGFhWe9bElNdJyuJLB+cLc2/e6J6BotxgpvmXCya4le
hdFTd9frB37Fk+wThaFGZ9eaCiXDnDnGkNOxkJdo+wG1HXadFXN9T2sPTX4/RJpd
EsS57a/fMUd/t9a/ieBfn23whv6lsPUoh5bYlnamIpRVna2t4lya5AxHSfzuXH28
R8lLP3NI4X0U7IzVchqOTj9MmubCAo2zOKVpqwIDAQABAoIBAQCkk0TwW89hOWMU
I06ZVBkoceV9WgDvC2O3Gn1w0AqgkQV5mA6ABIJy0KkpmSzabh7E4t0dNhvuTCMB
tzMOkjcflPZ7YJztGdXuqtVcF//gPfTkeS0GriRxRTk5wM46ZpzcsNS1+QfwfkmA
Wo0u8MG+5LFYOjtA7+50TuL17ko42KGh299HBUA8H4Svje1rOyp/Oot4g1Ujz1h4
1D5a3VZQWaD69FhAVNbLZWHPZxwopKGe9oBN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OyIUE1dSnkun0k9s//7Yr8TT17EQ5d1UhplMsz+NLethX63H/spLxzoMi2XfGSyb9FYhR2t+r6q6ranLiTYrcAgxqtmP1FloA0JaWAO8AYWFZ71sSU10nK4ksH5wtzb97onoGi3GCm+ZcLJriV6F0VN31+sHfsWT7BOFoUZn15oKJcOcOcaQ07GQl2j7AbUddp0Vc31Paw9Nfj9Eml0SxLntr98xR3+31r+J4F+fbfCG/qWw9SiHltiWdqYilFWdra3iXJrkDEdJ/O5cfbxHyUs/c0jhfRTsjNVyGo5OP0ya5sICjbM4pWmr 

1c:88:5c:dd:3f:67:43:ed:7b:36:5f:44:06:97:63:07

+--[ RSA 2048]----+
|      .. .    E+o|
|   . o .. .   .==|
|    o . .  . ..+o|
|       . .  o + o|
|        S    + o.|
|               o+|
|               .=|
|                .|
|                 |
+-----------------+

With full options:

var keygen = require('ssh-keygen2')
  , assert = require('assert')
 
var opts = {
  type: 'rsa',
  bits: 4096,
  comment: 'carlos8f',
  passphrase: 'this will encrypt the private key',
  location: '/path/to/id_rsa',
  keep: true, // this will keep the resulting files
  comment: 'optional comment for ssh public key'
};
 
keygen(opts, function (err, keypair) {
  assert.ifError(err);
  console.log(keypair.private);
  console.log(keypair.public);
  console.log(keypair.fingerprint + '\n');
  console.log(keypair.randomart + '\n');
});

This outputs:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,B134A7BE67B71FBA48E71135C89C7622

0ruw1vPNXY/xQgmWsyR54TFWaLG+MqWHJ1fWvhiChGyRgnrKHHThiBQAg81GAViC
xU6Jd0m9NTK3t9199SKKCHGZbIRqZI80ncrH5I38ITtBw4VCJ20yLvc+qbvT+Sh0
aCSifnpR1bMG4drzLKt6rngB2RAXO/AZBo/qYr41F6g2wEtoky4XE23fpEnevqmf
T46YqZ/v1hnaun8W0iKMKRC9ZJKfA/2L/7DQqQIbtsHB3cKCSWXuC5xYBDyYynAN
6u3J6PdHZqDrD9NZrBtw3S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OcjiL/62fkwngozqwETuFE8eJhn8J2pfScdl4faAtw1WYqaWNN27YwV6RvsfVmxE5Y0qiA7vwJL2CewOOgpyWryH/i2dhpdBTO9Rbcd+jfaVeJ2bd4Jmuj5rybSb7Gcy6YaPijsSZyioVnxgroO4xiklrD2rjCiqA4+0+9v4f7WZ3m2IpJFYKK3mgRgNnScnn8VMyT782UXPnd/To2dDNcvTHmKyTPoELve8utC4gjOcYXT1+SFOyPs9NvyNpbXECUaMj9hLX7WEcxGCjJL7UCiNv/yJwlHyunZR0mY7f18sYVWvCk3RfBtjLrMDmhHliFy8t/uKGq9J5R0JoJhDRkfHy7BdLKlBkVXezNnd7sDSjoIYB0aLRxCYo2D+tGBkav/L+AeWRnXE9U5fgL+iDSBcgAwBtGZvzskpgyav5ZQ== optional comment for ssh public key

ed:8c:0e:31:14:e7:f6:58:6b:51:10:9c:66:44:4d:5c optional comment for ssh public key

+--[ RSA 4096]----+
|      . .+=Bo.E  |
|       +  =.o    |
|      . ooo      |
|     . . = o     |
|      o S =      |
|       o =       |
|      . . o      |
|       o         |
|        .        |
+-----------------+

Developed by Terra Eclipse

Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Aptos, CA and Washington, D.C.


License: MIT

  • Copyright (C) 2014 Carlos Rodriguez (http://s8f.org/)
  • Copyright (C) 2014 Terra Eclipse, Inc. (http://www.terraeclipse.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Install

npm i ssh-keygen2

DownloadsWeekly Downloads

92

Version

0.1.0

License

MIT

Last publish

Collaborators

  • avatar