The output of the generated keys is not defined for both the private and public keys. Refer to [ssh-keygen][1]
Keys successfully created!
Private key: undefined
Public key: undefined
async generateAndWriteSSHKeyv2() {
return new Promise((resolve, reject) => {
let currentTime = new Date().getTime();
var location = path.join(process.cwd(), `contents/apps/SSHkeys/key_${currentTime}`);
var comment = 'example';
var password = 'example';
var format = 'PEM';
keygen({
location: location,
comment: comment,
password: password,
read: true,
destroy: false,
format: format,
size: 4096,
}, (err, output) => {
if (err) resolve(console.log('An error occurred: ' + err));
console.log('Keys successfully created!');
console.log('Private key: ' + output.key);
console.log('Public key: ' + output.pubKey);
resolve({
location,
comment,
password,
read: true,
format,
size: 4096,
output
})
});
})
};