1 | Tunnel-SSH
|
2 | ==========
|
3 |
|
4 | ![Tunnel-SSH Logo](http://i.imgur.com/I5PRnDD.jpg)
|
5 |
|
6 | Tunnel-ssh is based on the fantastic [ssh2](https://github.com/mscdex/ssh2) library by Brian White.
|
7 | Trouble ? Please study the ssh2 configuration.
|
8 |
|
9 | v2.0.0 Released !
|
10 | We're happy to introduce "reverse Tunnel"
|
11 |
|
12 |
|
13 | ## Howto
|
14 |
|
15 | Pro tip:
|
16 | If you plan to expose a local port on a remote machine you need to
|
17 | enable the "GatewayPorts" option in your 'sshd_config'
|
18 |
|
19 | ```sh
|
20 | # What ports, IPs and protocols we listen for
|
21 | Port 22
|
22 | GatewayPorts yes
|
23 | ```
|
24 |
|
25 |
|
26 | ####map remote port to localhost:
|
27 | ```js
|
28 | var tunnel = require('tunnel-ssh');
|
29 | //map port from remote 3306 to localhost 3306
|
30 | var server = tunnel({host: '172.16.0.8', dstPort: 3306}, function (error, result) {
|
31 | //you can start using your resources here. (mongodb, mysql, ....)
|
32 | console.log('connected');
|
33 | });
|
34 | ```
|
35 |
|
36 | ####remap remote port to localhost
|
37 | ```js
|
38 | // add a localPort for more more control
|
39 | var config = {
|
40 | host: '172.16.0.8',
|
41 | username: 'root',
|
42 | dstPort: 3306,
|
43 | localPort: 3000
|
44 | };
|
45 |
|
46 | var server = tunnel(config, function (error, result) {
|
47 | console.log('connected');
|
48 | });
|
49 | ```
|
50 |
|
51 | You can find more examples here
|
52 |
|
53 |
|
54 |
|
55 | tunnel-ssh supports the default ssh2 configuration.
|
56 | ```js
|
57 | // Or use a full blown ssh2 config, to fit your needs..
|
58 | {
|
59 | username: 'root',
|
60 | port: 22,
|
61 | srcPort: 0,
|
62 | srcHost: 'localhost',
|
63 | dstPort: null,
|
64 | dstHost: 'localhost',
|
65 | localHost: 'localhost'
|
66 | agent : process.env.SSH_AUTH_SOCK,
|
67 | privateKey:require('fs').readFileSync('/here/is/my/key'),
|
68 | password:'secret'
|
69 | }
|
70 |
|
71 | ```
|