Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tunnel-ssh

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tunnel-ssh

Easy extendable SSH tunnel

  • 4.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
152K
increased by4.6%
Maintainers
1
Weekly downloads
 
Created

What is tunnel-ssh?

The tunnel-ssh npm package allows you to create SSH tunnels in Node.js applications. This can be useful for securely connecting to remote servers, databases, or other services that require SSH tunneling.

What are tunnel-ssh's main functionalities?

Basic SSH Tunnel

This code sample demonstrates how to set up a basic SSH tunnel using the tunnel-ssh package. The configuration object includes details such as the SSH username, host, port, destination host and port, local host and port, and the private key for authentication.

const tunnel = require('tunnel-ssh');

const config = {
  username: 'user',
  host: 'remote.server.com',
  port: 22,
  dstHost: '127.0.0.1',
  dstPort: 27017,
  localHost: '127.0.0.1',
  localPort: 27017,
  privateKey: require('fs').readFileSync('/path/to/private/key')
};

tunnel(config, function (error, server) {
  if (error) {
    console.error('SSH connection error: ', error);
  } else {
    console.log('SSH tunnel established');
  }
});

SSH Tunnel with Forwarding

This code sample shows how to set up an SSH tunnel with port forwarding. The 'keepAlive' option is set to true to maintain the connection. This is useful for applications that need to keep a persistent connection to a remote database or service.

const tunnel = require('tunnel-ssh');

const config = {
  username: 'user',
  host: 'remote.server.com',
  port: 22,
  dstHost: '127.0.0.1',
  dstPort: 3306,
  localHost: '127.0.0.1',
  localPort: 3306,
  privateKey: require('fs').readFileSync('/path/to/private/key'),
  keepAlive: true
};

tunnel(config, function (error, server) {
  if (error) {
    console.error('SSH connection error: ', error);
  } else {
    console.log('SSH tunnel with forwarding established');
  }
});

Dynamic Port Forwarding

This code sample demonstrates how to set up a dynamic SSH tunnel, which can be used as a SOCKS proxy. The 'dynamic' option is set to true, allowing the tunnel to dynamically forward traffic to different destinations.

const tunnel = require('tunnel-ssh');

const config = {
  username: 'user',
  host: 'remote.server.com',
  port: 22,
  dstHost: '0.0.0.0',
  dstPort: 0,
  localHost: '127.0.0.1',
  localPort: 1080,
  privateKey: require('fs').readFileSync('/path/to/private/key'),
  dynamic: true
};

tunnel(config, function (error, server) {
  if (error) {
    console.error('SSH connection error: ', error);
  } else {
    console.log('Dynamic SSH tunnel established');
  }
});

Other packages similar to tunnel-ssh

Keywords

FAQs

Package last updated on 07 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc