question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

forwardOut() fails with Connection refused error with some remote hosts

See original GitHub issue

When I try to forward a local port to a remote host with this module and some hosts refuse to connect and I get the following error (DEBUG):

   Error: (SSH) Channel open failure: Connection refused
       at SSH2Stream.onFailure (c:\vncclient\node_modules\ssh2\lib\client.js:1186:13)
       at Object.onceWrapper (events.js:315:30)
       at emitOne (events.js:116:13)
       at SSH2Stream.emit (events.js:211:7)
       at parsePacket (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:3708:10)
       at SSH2Stream._transform (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:669:13)
       at SSH2Stream.Transform._read (_stream_transform.js:186:10)
       at SSH2Stream._read (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:251:15)
       at SSH2Stream.Transform._write (_stream_transform.js:174:12)
       at doWrite (_stream_writable.js:387:12) +0ms

the ‘ready’ event is hit but then the forwardOut() fails and therefore the sshstream cannot be piped to the connection.

This is my implementation I provide the configuration and wait for the ‘listening’ event and then create a new connection to the tunnel.

   const config = {
        username: 'myuser',
        privateKey: fs.readFileSync('file.ppk'),
        passphrase: 'mypasphrase',
        host: target_host,
        dstPort: 5900,
        localPort: 0,
        localHost: 'localhost',
        readyTimeout: 99999,
        srcHost: 'localhost',
        port: 22,
    };
    sshtunnel = tunnel(config, function (error, server) {
        if (error) {console.log('error');
    });
    sshtunnel.on('listening', function () { 
        net.createConnection(sshtunnel.address().port, sshtunnel.address().address, function () {
        });
 });

The above code works with some hosts but others Refuse, and all host are identical. I already spent 3 full days on this issue.

This is the complete debug output from tunnel-ssh:

  tunnel-ssh sshConnection:ready +224ms
Error found on ssh tunnel: { Error: (SSH) Channel open failure: Connection refused
    at SSH2Stream.onFailure (c:\vncclient\node_modules\ssh2\lib\client.js:1186:13)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at SSH2Stream.emit (events.js:211:7)
    at parsePacket (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:3708:10)
    at SSH2Stream._transform (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:669:13)
    at SSH2Stream.Transform._read (_stream_transform.js:186:10)
    at SSH2Stream._read (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:251:15)
    at SSH2Stream.Transform._write (_stream_transform.js:174:12)
    at doWrite (_stream_writable.js:387:12) reason: 'CONNECT_FAILED', lang: '' }
  tunnel-ssh Destination port: { Error: (SSH) Channel open failure: Connection refused
    at SSH2Stream.onFailure (c:\vncclient\node_modules\ssh2\lib\client.js:1186:13)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at SSH2Stream.emit (events.js:211:7)
    at parsePacket (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:3708:10)
    at SSH2Stream._transform (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:669:13)
    at SSH2Stream.Transform._read (_stream_transform.js:186:10)
    at SSH2Stream._read (c:\vncclient\node_modules\ssh2-streams\lib\ssh.js:251:15)
    at SSH2Stream.Transform._write (_stream_transform.js:174:12)
    at doWrite (_stream_writable.js:387:12) reason: 'CONNECT_FAILED', lang: '' } +6ms 

I’m running on a windows server 2012 with Node.js version 8.9.0 and the remote hosts are Linux 2.6.15.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mscdexcommented, Nov 6, 2017

@aberbegall i’d try adding ssh.shell() and then do ssh.forwardOut() inside the shell callback and see if that works.

0reactions
agebrockcommented, Nov 8, 2017

Glad you found a solution for you problem.

On 8 November 2017 at 03:25, Agustin Berbegall notifications@github.com wrote:

Closed #60 https://github.com/agebrock/tunnel-ssh/issues/60.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/agebrock/tunnel-ssh/issues/60#event-1330528411, or mute the thread https://github.com/notifications/unsubscribe-auth/AAL-p96Ydq3yaPh7CN4YUU4odsq3zfmKks5s0LyigaJpZM4QSYDc .

Read more comments on GitHub >

github_iconTop Results From Across the Web

ssh tunnel refusing connections with "channel 2: open failed"
Problem solved: $ ssh -L 7000:127.0.0.1:7000 user@host -N -v -v ...apparently, 'localhost' was not liked by the remote host. Yet, remote /etc/hosts contains ......
Read more >
How to Fix the SSH "Connection Refused" Error
Then we'll explain some common reasons your connection may be refused, including in PuTTY. Finally, we'll provide some troubleshooting tips.
Read more >
Forward X11 failed: Network error: Connection refused
I want to run startx via PuTTY and Xming. But, it produces this error: PuTTY X11 proxy: unable to connect to forwarded X...
Read more >
ssh2
Server events; Server methods; Connection events ... Host: 127.0.0.1:8000 ... console.log('FIRST :: forwardOut error: ' + err);.
Read more >
Troubleshooting
Issue the following command to obtain the current level of Java: ... Connection to remote machine refused, Older version of the keys is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found