reverse-tunnel-ssh-privatekey

Updated version of agebrock's reverse-tunnel-ssh which allows for SSH login using private key.

Usage no npm install needed!

<script type="module">
  import reverseTunnelSshPrivatekey from 'https://cdn.skypack.dev/reverse-tunnel-ssh-privatekey';
</script>

README

reverse-tunnel-ssh-privatekey

Easy ssh reverse tunnel

Tunnel-SSH Logo

How to use

npm i reverse-tunnel-ssh-privatekey (--save)

// Tunnel your local port 8000 to tunneltest.com:8000

//tunnel is a ssh2 clientConnection object
var tunnel = require('reverse-tunnel-ssh-privatekey');
tunnel({
  host: 'tunneltest.com',
  username: 'root',
  //privateKey: require('fs').readFileSync('/path_to_RSA_key'),
  dstHost: '0.0.0.0', // bind to all IPv4 interfaces
  dstPort: 8000,
  //srcHost: '127.0.0.1', // default
  //srcPort: dstPort // default is the same as dstPort
}, function(error, clientConnection) {
  //
});

// Tunnel your local port 8000 to a free port on tunneltest.com

var conn = tunnel({
  host: 'tunneltest.com',
  username: 'somebody',
  //privateKey: require('fs').readFileSync('/path_to_RSA_key'),
  dstHost: '0.0.0.0', // bind to all IPv4 interfaces
  dstPort: 0, // dynamically choose an open port on tunneltest.com
  //srcHost: '127.0.0.1', // default
  srcPort: 8000, // must be specified if dstPort=0
}, function (error, clientConnection) {
  //
});
conn.on('forward-in', function (port) {
  console.log('Forwarding from tunneltest.com:' + port);
});

If you plan to expose a local port on a remote machine (external interface) you need to enable the "GatewayPorts" option in your 'sshd_config'

# What ports, IPs and protocols we listen for
Port 22
GatewayPorts yes