{"id":17736606,"url":"https://github.com/parro-it/open-ssh-tunnel","last_synced_at":"2025-06-12T15:34:46.414Z","repository":{"id":57315115,"uuid":"47208440","full_name":"parro-it/open-ssh-tunnel","owner":"parro-it","description":"Easy ssh2 tunneling","archived":false,"fork":false,"pushed_at":"2020-06-03T09:19:04.000Z","size":55,"stargazers_count":53,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-02T20:45:24.716Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parro-it.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-01T18:14:19.000Z","updated_at":"2024-08-17T13:49:46.000Z","dependencies_parsed_at":"2022-09-18T20:51:36.628Z","dependency_job_id":null,"html_url":"https://github.com/parro-it/open-ssh-tunnel","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/parro-it/open-ssh-tunnel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parro-it%2Fopen-ssh-tunnel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parro-it%2Fopen-ssh-tunnel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parro-it%2Fopen-ssh-tunnel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parro-it%2Fopen-ssh-tunnel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parro-it","download_url":"https://codeload.github.com/parro-it/open-ssh-tunnel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parro-it%2Fopen-ssh-tunnel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259494003,"owners_count":22866425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-26T00:23:43.901Z","updated_at":"2025-06-12T15:34:46.395Z","avatar_url":"https://github.com/parro-it.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# open-ssh-tunnel\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/parro-it/open-ssh-tunnel.svg)](https://greenkeeper.io/)\n\n\u003e Easy ssh tunneling function based on [ssh2 library](https://github.com/mscdex/ssh2)\n\n\u003e Inspired by [tunnel-ssh](https://github.com/Finanzchef24-GmbH/tunnel-ssh), but with simplified, more modern code.\n\n[![Travis Build Status](https://img.shields.io/travis/parro-it/open-ssh-tunnel/master.svg)](http://travis-ci.org/parro-it/open-ssh-tunnel)\n[![NPM module](https://img.shields.io/npm/v/open-ssh-tunnel.svg)](https://npmjs.org/package/open-ssh-tunnel)\n[![NPM downloads](https://img.shields.io/npm/dt/open-ssh-tunnel.svg)](https://npmjs.org/package/open-ssh-tunnel)\n\n## Installation\n\n```bash\nnpm install --save open-ssh-tunnel\n```\n\n## Usage\n\n```js\n  const openSshTunnel = require('open-ssh-tunnel');\n  async function openATunnel() {\n    const server = await openSshTunnel({\n      host: 'your.server.address.com',\n      username: 'you',\n      password: 'secret',\n      srcPort: 3306,\n      srcAddr: '127.0.0.1',\n      dstPort: 3306,\n      dstAddr: '127.0.0.1',\n      readyTimeout: 1000,\n      forwardTimeout: 1000,\n      localPort: 3306,\n      localAddr: '127.0.0.1'\n    });\n\n    // you can now connect to your\n    // forwarded tcp port!\n\n    // later, when you want to close the tunnel\n    server.close();\n  }\n\n```\n### Example\n\n```\n╭───────────────╮      ╭─────────────────╮      ╭─────────╮      ╭─────────╮\n│ Mongo         │      │ open-ssh-tunnel │      │ SSH     │      │ Mongo   │\n│ client        │ \u003c--\u003e │                 │ \u003c--\u003e │ server  │ \u003c--\u003e │ server  │\n│ 192.168.1.1   │      │ 192.168.1.2     │      │ 10.0.0.2│      │ 10.0.0.1│\n│               │      │                 │      │         │      │         │\n╰───────────────╯      ╰─────────────────╯      ╰─────────╯      ╰─────────╯\n```\n\nIn scenario where you want to connect to `mongo` that runs on a remote host, you should provide the following configuration.\n\n```js\n{\n    destPort: 27017,\n    destAddr: '10.0.0.1',\n    host: '10.0.0.2',\n    port: 22,\n    localAddr: 27018,\n    localPort: '192.168.1.2',\n    srcAddr: '192.168.1.1',\n    srcPort: 27019,\n    ...\n}\n```\n\nNote that you have to provide __localAddr__ when you need to make the tunnel visible to other hosts in your LAN.\n\n__srcAddr__ and __srcPort__, when provided, should be the network address of a client host connecting to your SSH tunnel local endpoint. If you do not need them you can provide any value for the arguments.\n\n## API\n\nThe module exports `openSshTunnel` function. It return a promise that resolve\nto a node net server instance if tunnel is opened, otherwise is rejected with an error.\n\n### Options\n\n* __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](https://github.com/mscdex/ssh2/blob/master/README.md#api).\n\n* forwardTimeout - How many millisecond to wait before reject with a timeout error.\n\n* __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.\n\n* All other options are passed to [ssh2 `Client.connect` method](https://github.com/mscdex/ssh2/blob/master/README.md#api).\n\n\n## Related\n\n* [electron-tunnel](https://github.com/parro-it/tunnels) - Awesome Electron app to manage your ssh tunnels - powered by this module.\n\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 parro-it\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparro-it%2Fopen-ssh-tunnel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparro-it%2Fopen-ssh-tunnel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparro-it%2Fopen-ssh-tunnel/lists"}