0

I have vpn access, so i can ssh to server by following command from terminal

ssh qa-trinath01.my-qa

Its working fine from terminal.

But from nodejs, its not working. my code is

var express = require("express");
var app = express();
var node_ssh = require('node-ssh')
var

ssh = new node_ssh()

ssh.connect({
        host: 'qa-trinath01.my-qa',
        username: 'tanantham',
        port: 27017,
        privateKey: '/Users/tanantham/.ssh/id_rsa'
    }).then(function() {
        console.error('Success: ');
    }).catch((error) => {
        console.error('ERROR: ', error);
    });;

app.listen(3001);

I am getting output as

ERROR:  { Error: getaddrinfo ENOTFOUND qa-trinath01.my-qa qa-trinath01.my-qa:27017
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'qa-trinath01.my-qa',
  host: 'qa-trinath01.my-qa',
  port: 27017,
  level: 'client-socket' }

Can some one suggest the nodejs code to connect to ssh, i have only ssh key and ssh server name details.

ssh key ->  /Users/tanantham/.ssh/id_rsa
server name -> qa-trinath01.my-qa
trinath
  • 433
  • 1
  • 5
  • 19
  • What about this https://stackoverflow.com/a/28385129/3957754 ? Also you can try with another language in order to validate if it is an error in node.js or a network issue. – JRichardsz Dec 04 '18 at 23:16
  • you can give node-ssh a spin. Here is a tutorial: https://grizzlybit.info/blog/how-to-ssh-using-nodejs – zubair1024 Sep 25 '20 at 17:12

1 Answers1

-1

Have you tried to replace 'privateKey' with 'password' and enter your password. It's probably not the most secure but it normally works. Unless you have to use your private key from id-rsa

ssh = new node_ssh()

ssh.connect({
        host: 'qa-trinath01.my-qa',
        username: 'tanantham',
        port: 27017,
        password: 'YourPasswordHere'
    }).then(function() {
        console.error('Success: ');
    }).catch((error) => {
        console.error('ERROR: ', error);
    });;

app.listen(3001);
Bazinga
  • 21
  • 4
  • According to the docs https://www.npmjs.com/package/node-ssh privateKey is fine?? – Dan Rayson Dec 04 '18 at 16:26
  • 1
    Yes it's fine but password work's too, according to the docs.. http://github.com/mscdex/ssh2#client-methods – Bazinga Dec 04 '18 at 16:35
  • The actual error says "getaddrinfo ENOTFOUND" Do you think this might be relevant? p.s. I stand corrected on the first comment :) Although, do we know if they're using user-based or host-based auth? – Dan Rayson Dec 04 '18 at 16:41
  • You're right, my solution is more of a workaround than a solution. But "getaddrinfo ENOTFOUND" means client was not able to connect to given address so if it's working from terminal i guess it's an authentification issue. We don't know if it's used-based or host-based auth, do we? – Bazinga Dec 04 '18 at 17:00
  • Exactly ;) We don't know. Assume makes an 'ass' out of 'u' and 'me' :) It would be nice if Trinath could give us more info... I'll leave this with you, I have no expertise with this question tbh. It's just "Did you try?" type of answers don't tend to be correct, so I thought I'd chime in and try to move it along a bit. I did not succeed :( – Dan Rayson Dec 05 '18 at 14:18
  • Indeed, I will no longer answer by "Did you try" but for my defense this is my first answer :D It would be nice if Trinath could give us a feedback on his problem. – Bazinga Dec 05 '18 at 15:31