Coder Social home page Coder Social logo

ssh-key-files's Introduction

ssh-key-files Build Status

Asynchronously returns an object containing ssh-keyfile pairs of the current user

Install

$ npm install ssh-key-files

Usage

const sshKeyFiles = require('ssh-key-files');

await sshKeyFiles();
//=> {unicorn: '/Users/dr-evil/.ssh/unicorn'}

// Search a custom directory instead
await sshKeyFiles('/temp');
//=> {garbage: '/temp/garbage'}

API

sshKeyFiles([dir])

Asynchronously searches at the users ssh-directory for private/public key-file pairs. It estimates the given file pairs share the same basename where the private name has no file-extension and the public keyfile ends with .pub.

The Promise returns private keyfile-basename / private keyfile-path pairs, if both, the private as well as the public file, exist.

Example:

    {
      github: '/Users/unicorn/.shh/github',
      gitlab_rsa: '/Users/unicorn/.shh/gitlab_rsa'
    }

⚠️ The file permissions are not checked.

The public keyfile can be easily derived by adding the .pub-extension manually:

    const keyFiles = await sshKeyFiles();
    const privateKeyFile = keyFiles.unicorn; //=> /Users/dr-evil/.ssh/unicorn
    const publicKeyFile = `${privateKeyFile}.pub`; //=> /Users/dr-evil/.ssh/unicorn.pub

You might, of course, use the thenable-syntax:

    let privateKeyFile;
    let publicKeyFile;

    sshKeyFiles()
    .then(keyFiles => {
        privateKeyFile = keyFiles.unicorn; //=> /Users/dr-evil/.ssh/unicorn
        publicKeyFile = `${privateKeyFile}.pub`; //=> /Users/dr-evil/.ssh/unicorn.pub
    });

dir (optional)

Type: string

Alternative path to search for files with a corresponding .pub-file. Defaults to the users .ssh-folder (located at the users os-specific home directory).

License

MIT © Florian Breisch

ssh-key-files's People

Contributors

florianb avatar

Watchers

James Cloos avatar  avatar

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.