Giter Club home page Giter Club logo

ssh-keygen's Introduction

ssh-keygen

Generates a SSH key-pair

Install

  1. Make sure you have ssh-keygen (try $ ssh-keygen if you aren't sure)
  2. npm package install
npm install ssh-keygen

OR download from github and place in ./node_modules

Usage

var keygen = require('ssh-keygen');
var fs = require('fs');

var location = __dirname + '/foo_rsa';
var comment = '[email protected]';
var password = 'keypassword'; // false and undefined will convert to an empty pw
var format = 'PEM'; // default is RFC4716

keygen({
  location: location,
  comment: comment,
  password: password,
  read: true,
  format: format
}, function(err, out){
	if(err) return console.log('Something went wrong: '+err);
	console.log('Keys created!');
	console.log('private key: '+out.key);
	console.log('public key: '+out.pubKey);
});

The following shell command will get executed:

$ ssh-keygen -t rsa -b 2048 -C "[email protected]" -N "keypassword" -m PEM -f ./foo_rsa
Generating public/private rsa key pair.
Your identification has been saved in ./foo_rsa.
Your public key has been saved in ./foo_rsa.pub.
The key fingerprint is:
02:f7:40:b6:c7:b3:a3:68:16:53:dd:86:63:df:b5:33 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|      o          |
|     o + o       |
|    . = O o   .  |
|     + = * . . . |
|    o . S . . E  |
|     + o .     o |
|    + .          |
|   o             |
|                 |
+-----------------+

Parameters

  • location, desired location for the key. The public key will be at the location + .pub, defaults temp dir
  • read, should the callback have the key files read into it, defaults true
  • force, destroy pre-existing files with the location name and the public key name, defaults true
  • destroy, destroy the key files once they have been read, defaults false
  • comment, the comment that should be embedded into the key, defaults empty
  • password, the password for the key, defaults empty

Note

It is advisable to generate your keys on a machine with a significant random source like one with a mouse/trackpad.

License

ssh-keygen is open source under the MIT license

Windows

This package bundles binaries for windows. The current version is: 2.4.4.2-rc3

Todo

  • Real tests

Contributors welcome!

ssh-keygen's People

Contributors

bronzehedwick avatar ericvicenti avatar franck34 avatar lihaorong840506 avatar linusu avatar pandres95 avatar pjvds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ssh-keygen's Issues

Destroy-option defaults to true instead of false

Hi,

I was wondering where the keyfiles went, because the documentation says:
destroy, destroy the key files once they have been read, defaults false
but in ssh-keygen.js in line #102 destroy defaults to true:
if(_.isUndefined(opts.destroy)) opts.destroy = true;

Please change either the documentation or the readme.

Thanks, Gerald

Support for Promises, (async/await)

keygen function is normal function not Promise or async function. I confused for a while and realized it may want some async methods.

code

keygen({
  location: location,
  comment: comment,
  password: password,
  read: true,
  format: format
}, function(err, out){
    console.log('111')
    fs.writeFile('aaa',out.key)
});
console.log('222')

result

222
111

Async Await

Is it possible to promisify this package so that it can be used with Async Await?

windows generate process fail

ssh-keygen is a good tool to make a ssh key easily. But when I use it on window 7 system. It would fail. the callback will not return error object at the same time.

I look up the source code and find the bin which the program use . I click it directly. It throw a error like this

ssh-keygen-error

and I change the bin with portable msysgit bin portalble link using the files like

ssh-keygen-bin

It work again.

I hope the problem can be solved to make the project better

extra space so private key is empty ?

hi

line 94

key = key.substring(0, key.lastIndexOf(" \n"));

On my side (linux) i have to remove the extra space before \n to have the private key in the callback when destroy:true.

If i i don't do that, key is empty.

What do you think ?

Thank you !

Package not working on windows

Tried to test using the code defined in 'usage'

var keygen = require('ssh-keygen');
var fs = require('fs');

var location = __dirname + '/foo_rsa';
var comment = '[email protected]';
var password = 'keypassword'; // false and undefined will convert to an empty pw

keygen({
  location: location,
  comment: comment,
    password: password,
  read: true
}, function(err, out){
    if(err) return console.log('Something went wrong: '+err);
    console.log('Keys created!');
    console.log('private key: '+out.key);
    console.log('public key: '+out.pubKey);
});

CMD OUTPUT

Keys created!
private key: undefined
public key: undefined

There was no file created

Bit Length Option

Hi

Nice module however I can't seem to leave passphrase empty and configure the bits length -is that right?

Thanks
Simon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.