Asynchronously returns an object containing ssh-keyfile pairs of the current user
$ npm install ssh-key-files
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'}
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
});
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).
MIT © Florian Breisch