{"id":15677600,"url":"https://github.com/sgreben/sshtunnel","last_synced_at":"2025-07-29T05:34:32.135Z","repository":{"id":57524644,"uuid":"162367012","full_name":"sgreben/sshtunnel","owner":"sgreben","description":"library providing a convenient dialer for SSH-tunneled TCP and Unix domain socket connections. #golang","archived":false,"fork":false,"pushed_at":"2019-02-28T12:09:55.000Z","size":37,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T00:47:54.080Z","etag":null,"topics":["golang","library","native-go","openssh-client","putty","ssh","tcp","tunnel","unix-socket"],"latest_commit_sha":null,"homepage":"","language":"Go","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/sgreben.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":"2018-12-19T01:40:47.000Z","updated_at":"2025-04-17T14:01:19.000Z","dependencies_parsed_at":"2022-09-10T23:55:13.326Z","dependency_job_id":null,"html_url":"https://github.com/sgreben/sshtunnel","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/sgreben/sshtunnel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fsshtunnel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fsshtunnel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fsshtunnel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fsshtunnel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgreben","download_url":"https://codeload.github.com/sgreben/sshtunnel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Fsshtunnel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267633674,"owners_count":24118777,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","library","native-go","openssh-client","putty","ssh","tcp","tunnel","unix-socket"],"created_at":"2024-10-03T16:09:58.232Z","updated_at":"2025-07-29T05:34:32.099Z","avatar_url":"https://github.com/sgreben.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sshtunnel\n\n[![](https://godoc.org/github.com/sgreben/sshtunnel?status.svg)](http://godoc.org/github.com/sgreben/sshtunnel) [![](https://goreportcard.com/badge/github.com/sgreben/sshtunnel/goreportcard)](https://goreportcard.com/report/github.com/sgreben/sshtunnel) [![cover.run](https://cover.run/go/github.com/sgreben/sshtunnel.svg?style=flat\u0026tag=golang-1.10)](https://cover.run/go?tag=golang-1.10\u0026repo=github.com%2Fsgreben%2Fsshtunnel) [![Build Status](https://travis-ci.org/sgreben/sshtunnel.svg?branch=master)](https://travis-ci.org/sgreben/sshtunnel)\n\nGo library providing a dialer for SSH-tunneled TCP and Unix domain socket connections. Please note the [**limitations**](#limitations) below.\n\nThe underlying package `golang.org/x/crypto/ssh` already provides a dialer `ssh.Client.Dial` that can establish `direct-tcpip` (TCP) and `direct-streamlocal` (Unix domain socket) connections via SSH.\n\nIn comparison, the functions `Dial/DialContext`, `ReDial/ReDialContext`, `Listen/ListenContext` in this package provide additional convenience features such as redialling dropped connections, and serving the tunnel locally.\n\nFurthermore, a wrapper [`github.com/sgreben/sshtunnel/exec`](http://godoc.org/github.com/sgreben/sshtunnel/exec) around (`exec`'d) external clients, with a similar interface as the native client, is provided.\n\n- [Get it](#get-it)\n- [Use it](#use-it)\n\t- [Docs](#docs)\n\t- [Toy example (native)](#toy-example-native)\n\t- [Toy example (external client)](#toy-example-external-client)\n\t- [Bigger examples](#bigger-examples)\n- [Limitations](#limitations)\n\n## Get it\n\n```sh\ngo get -u \"github.com/sgreben/sshtunnel\"\n```\n\n## Use it\n\n```go\nimport \"github.com/sgreben/sshtunnel\"\n```\n\n### Docs\n\n[![](https://godoc.org/github.com/sgreben/sshtunnel?status.svg)](http://godoc.org/github.com/sgreben/sshtunnel)\n\n\n### Toy example (native)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\n\t\"golang.org/x/crypto/ssh\"\n\t\"github.com/sgreben/sshtunnel\"\n)\n\nfunc main() {\n\t// Connect to \"google.com:80\" via a tunnel to \"ubuntu@my-ssh-server-host:22\"\n\tkeyPath := \"private-key.pem\"\n\tauthConfig := sshtunnel.ConfigAuth{\n\t\tKeys:     []sshtunnel.KeySource{{Path: \u0026keyPath}},\n\t}\n\tsshAuthMethods, _ := authConfig.Methods()\n\tclientConfig := ssh.ClientConfig{\n\t\tUser: \"ubuntu\",\n\t\tAuth: sshAuthMethods,\n\t\tHostKeyCallback: ssh.InsecureIgnoreHostKey(),\n\t}\n\ttunnelConfig := sshtunnel.Config{\n\t\tSSHAddr: \"my-ssh-server-host:22\",\n\t\tSSHClient: \u0026clientConfig,\n\t}\n\tconn, _, err := sshtunnel.Dial(\"tcp\", \"google.com:80\", \u0026tunnelConfig)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Do things with conn\n\tfmt.Fprintln(conn, \"GET /\")\n\tio.Copy(os.Stdout, conn)\n}\n```\n\n### Toy example (external client)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"time\"\n\n\t\"github.com/sgreben/sshtunnel/exec\"\n)\n\nfunc main() {\n\t// Connect to \"google.com:80\" via a tunnel to \"ubuntu@my-ssh-server-host:22\"\n\t//\n\t// Unlike the \"native\" example above, here a binary named `ssh` (which must be in $PATH)\n\t// is used to set up the tunnel.\n\ttunnelConfig := sshtunnel.Config{\n\t\tUser:            \"ubuntu\",\n\t\tSSHHost:         \"my-ssh-server-host\",\n\t\tSSHPort:         \"22\",\n\t\tCommandTemplate: sshtunnel.CommandTemplateOpenSSH,\n\t\tCommandConfig: func(cmd *exec.Cmd) error {\n\t\t\tcmd.Stdout = os.Stdout\n\t\t\tcmd.Stderr = os.Stderr\n\t\t\tcmd.Stdin = os.Stdin\n\t\t\treturn nil\n\t\t},\n\t}\n\n\ttunnelConfig.Backoff.Min = 50 * time.Millisecond\n\ttunnelConfig.Backoff.Max = 1 * time.Second\n\ttunnelConfig.Backoff.MaxAttempts = 8\n\n\tconn, _, err := sshtunnel.Dial(\"google.com:80\", \u0026tunnelConfig)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Do things with conn\n\tfmt.Fprintln(conn, \"GET /\")\n\tio.Copy(os.Stdout, conn)\n}\n```\n\n### Bigger examples\n\nProjects using this library:\n\n\n- [docker-compose-hosts](https://github.com/sgreben/docker-compose-hosts).\n- [with-ssh-docker-socket](https://github.com/sgreben/with-ssh-docker-socket).\n\n## Limitations\n\n- **No tests**; want some - write some.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgreben%2Fsshtunnel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgreben%2Fsshtunnel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgreben%2Fsshtunnel/lists"}