Skip to content

Instantly share code, notes, and snippets.

@marcsolanadal
Last active October 27, 2015 13:37
Show Gist options
  • Save marcsolanadal/6ee4bd4983927aab4477 to your computer and use it in GitHub Desktop.
Save marcsolanadal/6ee4bd4983927aab4477 to your computer and use it in GitHub Desktop.
Shell.exec("ssh-keyscan"
+ " -p " + parsedUrl.port
+ " -t rsa "
+ parsedUrl.hostname, function(code, output) {
var commentedKey = output.split('\n');
var key = commentedKey[1].split(' ');
publicKey = key[1] + ' ' + key[2];
hostString = '[' + parsedUrl.hostname + ']:' + parsedUrl.port
+ ',[' + remoteIP + ']:' + parsedUrl.port
+ ' ' + publicKey + '\n';
knownHosts = (knownHosts == null) ? [''] : knownHosts.split('\n');
var inFile = false;
for (var i = 0; i < knownHosts.length; i++) {
if (hostString == knownHosts[i]) inFile = true; // <<<<<<<<<<<<<<<<<<<<
}
if(inFile == false) {
hostString.toEnd(knownHostPath);
reply('New key added into the known_hosts');
}
else {
reply('The key is already in known_hosts');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment