SSH Tunnel Port Forwarding
Hello, i'm trying to do a version of this command with ssh2.client, tried with fordward out but it didn't work.
The command: ssh -fNg -L local-port:localhost:remote-port username@server;
The code i tried:
conn.on('ready', () => {
conn.forwardOut(
'localhost',
localPort,
server,
remotePort, function (err, stream) {
if (err) throw err;
}).connect({
host: server
port: 22
username: username
privateKey: sshKey
});
When i check with lsof -i -P i dont see the local port.
Thanks in advance
That functionality isn't provided out of the box by this module. However there are other modules on npm that build on top of ssh2 that provide the local TCP port forwarding. All that's basically needed is net.createServer() and creating a new ssh connection per incoming socket, where you call conn.forwardOut() appropriately and then pipe between the local socket and the forwarded stream you get in your conn.forwardOut() callback.
Thanks for the quick reply, could you point me out some of those modules?
Great software BTW.
Just search npm's site for 'ssh tunnel' and you will find some. I have not personally used any of them, but here are a few of examples found during a quick search: tunnel-ssh, open-ssh-tunnel, and adit.
Hi @gach87, Did you manage to find a solution for the local port forward? I have a similar problem, I use plink for windows instead of ssh.