Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including open-ssh-tunnel with all npm packages installed. Try it out:

var openSshTunnel = require("open-ssh-tunnel")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

open-ssh-tunnel v0.3.1

Easy ssh2 tunneling


Easy ssh tunneling function based on ssh2 library

Inspired by tunnel-ssh, but with simplified, more modern code.

Travis Build Status NPM module NPM downloads


npm install --save open-ssh-tunnel


  const openSshTunnel = require('open-ssh-tunnel');
  async function openATunnel() {
    const server = await openSshTunnel({
      host: '',
      username: 'you',
      password: 'secret',
      srcPort: 3306,
      srcAddr: '',
      dstPort: 3306,
      dstAddr: '',
      readyTimeout: 1000,
      forwardTimeout: 1000,
      localPort: 3306,
      localAddr: ''

    // you can now connect to your
    // forwarded tcp port!

    // later, when you want to close the tunnel


The module exports openSshTunnel function. It return a promise that resolve to a node net server instance if tunnel is opened, otherwise is rejected with an error.


  • srcIP and srcPort as the originating address and port and dstIP and dstPort as the remote destination address and port. These are options passed to ssh2 Client.forwardOut method.

  • forwardTimeout - How many millisecond to wait before reject with a timeout error.

  • localAddr and localPort are the address and port of the local endpoint of the tunnel on your machine. They are passed to net server connect method.

  • All other options are passed to ssh2 Client.connect method.


  • electron-tunnel - Awesome Electron app to manage your ssh tunnels - powered by this module.


The MIT License (MIT)

Copyright (c) 2015 parro-it


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free