{"id":18440248,"url":"https://github.com/drowzy/ssh_tunnel","last_synced_at":"2025-04-07T21:33:06.265Z","repository":{"id":57552527,"uuid":"124662081","full_name":"drowzy/ssh_tunnel","owner":"drowzy","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-09T09:46:21.000Z","size":32,"stargazers_count":35,"open_issues_count":1,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T01:05:58.341Z","etag":null,"topics":["elixir","ssh","ssh-tunnel"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/drowzy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-10T14:13:21.000Z","updated_at":"2024-07-04T06:55:36.000Z","dependencies_parsed_at":"2024-11-06T06:31:53.800Z","dependency_job_id":"28570251-ef2f-4e0b-965e-1b3c8af1ee8c","html_url":"https://github.com/drowzy/ssh_tunnel","commit_stats":{"total_commits":33,"total_committers":1,"mean_commits":33.0,"dds":0.0,"last_synced_commit":"310c3796f054f2839d78ad6e457adf4c6f7075d4"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drowzy%2Fssh_tunnel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drowzy%2Fssh_tunnel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drowzy%2Fssh_tunnel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drowzy%2Fssh_tunnel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drowzy","download_url":"https://codeload.github.com/drowzy/ssh_tunnel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247732797,"owners_count":20986923,"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":["elixir","ssh","ssh-tunnel"],"created_at":"2024-11-06T06:29:12.249Z","updated_at":"2025-04-07T21:33:01.240Z","avatar_url":"https://github.com/drowzy.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SSHTunnel\n\nCreate SSH tunnels in Elixir\n\n[Documentation for SSHTunnel is available online.](https://hexdocs.pm/ssh_tunnel)\n\n## Installation\n\nAdd SSHTunnel to your `mix.exs` and run `mix deps.get`\n\n```elixir\ndef deps do\n  [\n    {:ssh_tunnel, \"~\u003e 0.1.3\"}\n  ]\nend\n```\n\n## Usage\n\nSSHTunnel can be used to create forwarded SSH channels, similair to channels created using `:ssh_connection`.\nSending messages can be done using `:ssh_connection.send/3`.\n\nSSHTunnel also provide on-demand created tunnels, this is eqvivalent to using `ssh -nNT -L 8080:sshserver.example.com:80 user@sshserver.example.com`.\nThe tunnel process will forward messages from a TCP client to a ssh connection and back.\n\n### As channels\n\n* `directtcp-ip`\n\n```elixir\nmsg = \"GET / HTTP/1.1\\r\\nHost: localhost:8080\\r\\nUser-Agent: ssht/0.1.1\\r\\nAccept: */*\\r\\n\\r\\n\"\n\n{:ok, pid} = SSHTunnel.connect(host: \"sshserver.example.com\", user: \"user\", password: \"password\")\n{:ok, ch} = SSHTunnel.direct_tcpip(pid, {\"127.0.0.1\", 8080}, {\"sshserver.example.com\", 80})\n:ok = :ssh_connection.send(pid, ch, msg)\nreceive do\n  {:ssh_cm, _, {:data, channel, _, data}} -\u003e IO.puts(\"Data: #{(data)}\")\nend\n```\n\n* `streamlocal forward`\n\n```elixir\nmsg = \"GET /images/json HTTP/1.1\\r\\nHost: /var/run/docker.sock\\r\\nAccept: */*\\r\\n\\r\\n\"\n\n{:ok, pid} = SSHTunnel.connect(host: \"sshserver.example.com\", user: \"user\", password: \"password\")\n{:ok, ch} = SSHTunnel.stream_local_forward(pid, \"/var/run/docker.sock\")\n:ok = :ssh_connection.send(pid, ch, msg)\n\nreceive do\n  {:ssh_cm, _, {:data, channel, _, data}} -\u003e IO.puts(\"Data: #{(data)}\")\nend\n```\n\n### Tunnels\n\n* `directtcp-ip`\n\n```elixir\n{:ok, ssh_ref} = SSHTunnel.connect(host: \"sshserver.example.com\", user: \"user\", password: \"password\")\n\n# Will start a tcp server listening on port 8080.\n# Any TCP messages received on `127.0.0.1:8080` will be forwarded to `sshserver.example.com:80`\n{:ok, pid} = SSHTunnel.start_tunnel(pid, {:tcpip, {8080, {\"sshserver.example.com\", 80}}})\n\n# Send a TCP message\n%HTTPoison.Response{body: body} = HTTPoison.get!(\"127.0.0.1:8080\")\nIO.puts(\"Received body: #{body})\n```\n\n* `streamlocal forward`\n\n```elixir\n{:ok, ssh_ref} = SSHTunnel.connect(host: \"sshserver.example.com\", user: \"user\", password: \"password\")\n\n# Will start a tcp server listening on the provided path.\n# Any TCP messages received on `/path/to/socket.socket` will be forwarded to the `/path/`to/remote.sock` on sshserver.example.com\n{:ok, pid} = SSHTunnel.start_tunnel(pid, {:local, {\"/path/to/socket.sock\", {\"sshserver.example.com\", \"/path/to/remote.sock\"}}})\n\n# Send a TCP message\n%HTTPoison.Response{body: body} = HTTPoison.get!(\"http+unix://#{URI.encode_www_form(\"/path/to/socket.sock\")}\")\nIO.puts(\"Received body: #{body})\n```\n\nIt is also possible to mix and match:\n\n```elixir\n# From a local port to a remote socket\n{:ok, pid} = SSHTunnel.start_tunnel(pid, {:tcpip, {8080, {\"sshserver.example.com\", \"/path/to/remote.sock\"}}})\n\n# From a local socket to a remote port\n{:ok, pid} = SSHTunnel.start_tunnel(pid, {:local, {\"/path/to/socket.sock\", {\"sshserver.example.com\", 80}}})\n```\n\n## Testing\n\n```bash\nmix test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrowzy%2Fssh_tunnel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrowzy%2Fssh_tunnel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrowzy%2Fssh_tunnel/lists"}