javascript – tunnel-ssh ECONNRESET – Stack Overflow

I’ve been trying to figure out why the connection is being close. I want to call the APIs from that server. When I do it in Putty or MobaXterm there’s no errors like this

const { readFileSync } = require('fs');

const tunnel = require('tunnel-ssh');
 * Setup ssh tunnel
var sshConfig = {
    username: process.env.SERVER_USERNAME,
    host: process.env.SERVER,
    port: process.env.SERVER_PORT,
    dstHost: process.env.LOCAL_HOST,
    dstPort: process.env.LOCAL_PORT,
    privateKey: readFileSync('./key.pem')

var ssh_server = tunnel(sshConfig, function (error, server) {
    if (error) {
        //catch configuration and startup errors here.
        console.log("SSH connection error: " + error);

    // Use a listener to handle errors outside the callback
    ssh_server.on('error', function (err) {

It gives me the error saying connection lost before handshake

Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read',
  level: 'client-socket'

I want it to create an ssh-tunnel without hiccups

Read more here: Source link