{"id":16699980,"url":"https://github.com/mavogel/go-ssh-forward","last_synced_at":"2025-04-10T03:50:56.797Z","repository":{"id":65198547,"uuid":"118912422","full_name":"mavogel/go-ssh-forward","owner":"mavogel","description":"A simple library to establish a forward via a jump host in go","archived":false,"fork":false,"pushed_at":"2025-01-06T16:12:07.000Z","size":55,"stargazers_count":6,"open_issues_count":10,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-02T19:05:33.229Z","etag":null,"topics":["forward","golang","jumphost","ssh"],"latest_commit_sha":null,"homepage":null,"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/mavogel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-01-25T12:51:58.000Z","updated_at":"2024-12-18T10:50:21.000Z","dependencies_parsed_at":"2024-11-11T09:25:29.630Z","dependency_job_id":"38ad599f-e498-4d1d-b2bb-60dd2597bf87","html_url":"https://github.com/mavogel/go-ssh-forward","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":"0.34782608695652173","last_synced_commit":"8b09f880dc7ff24b514f930c39419ed5cb483dd9"},"previous_names":["mavogel/sshforward"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavogel%2Fgo-ssh-forward","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavogel%2Fgo-ssh-forward/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavogel%2Fgo-ssh-forward/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavogel%2Fgo-ssh-forward/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mavogel","download_url":"https://codeload.github.com/mavogel/go-ssh-forward/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239132545,"owners_count":19587106,"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":["forward","golang","jumphost","ssh"],"created_at":"2024-10-12T18:08:45.743Z","updated_at":"2025-02-16T12:30:56.944Z","avatar_url":"https://github.com/mavogel.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/mavogel/go-ssh-forward)](https://pkg.go.dev/github.com/mavogel/go-ssh-forward)\n![Build Status](https://github.com/mavogel/go-ssh-forward/actions/workflows/lint.yml/badge.svg)\n[![Coverage Status](https://img.shields.io/coveralls/mavogel/go-ssh-forward.svg)](https://coveralls.io/r/mavogel/go-ssh-forward)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mavogel/go-ssh-forward)](https://goreportcard.com/report/github.com/mavogel/go-ssh-forward)\n\n# go-ssh-forward: A library for setting up a Forward via SSH in go\n## Table of Contents\n- [Motivation](#motivation)\n- [Usage](#usage)\n- [Inspiration](#inspiration)\n- [Releasee](#release)\n- [License](#license)\n\n## \u003ca name=\"motivation\"\u003e\u003c/a\u003eMotivation\nI wanted it to be possible to establish a tunnel like the following in `go`\n```sh\n$ ssh -f -L 2376:localhost:2376 \\ \n  -o ExitOnForwardFailure=yes \\ \n\t-o ProxyCommand=\"ssh -l jumpuser1 -i /Users/abc/.ssh/id_rsa_jump_host1 10.0.0.1 -W %h:%p\" \\ \n\t-o UserKnownHostsFile=/dev/null \\ \n\t-o StrictHostKeyChecking=no \\ \n\t-i /Users/abc/.ssh/id_rsa_end_host \\ \n\tendhostuser@20.0.0.1 \\\n\tsleep 10\n```\n\nIn this scenario the `end host` is only accessible via the `jump host`\n```\n    localhost:2376 --(j)--\u003e 10.0.0.1:22 --(e)--\u003e 20.0.0.1:2376 -\u003e 127.0.0.1:2376\n       `host A`              `jump host`          `end host          `end host`          \n```\n\n## \u003ca name=\"usage\"\u003e\u003c/a\u003eUsage\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"time\"\n\n    fw \"github.com/mavogel/go-ssh-forward\"\n)\nfunc main() {\n  forwardConfig := \u0026fw.Config{\n\t\tJumpHostConfigs: []*fw.SSHConfig{\n\t\t\t\u0026fw.SSHConfig{\n\t\t\t\tAddress:        \"10.0.0.1:22\",\n\t\t\t\tUser:           \"jumpuser1\",\n\t\t\t\tPrivateKeyFile: \"/Users/abc/.ssh/id_rsa_jump_host1\",\n\t\t\t},\n\t\t},\n\t\tEndHostConfig: \u0026fw.SSHConfig{\n\t\t\tAddress:        \"20.0.0.1:22\",\n\t\t\tUser:           \"endhostuser\",\n\t\t\tPrivateKeyFile: \"/Users/abc/.ssh/id_rsa_end_host\",\n\t\t},\n\t\tLocalAddress:  \"localhost:2376\",\n\t\tRemoteAddress: \"localhost:2376\",\n  }\n \n  forward, forwardErrors, bootstrapErr := fw.NewForward(forwardConfig)\n  handleForwardErrors(forward)\n  defer forward.Stop()\n  if bootstrapErr != nil {\n\t\tlog.Printf(\"bootstrapErr: %s\", bootstrapErr)\n\t\treturn\n  }\n  \n  // run commands against 127.0.0.1:2376\n  // ...\n\n}\n\nfunc handleForwardErrors(forwardErrors chan error) {\n\tgo func() {\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase forwardError := \u003c-forwardErrors:\n\t\t\t\tlog.Printf(\"forward err: %s\", forwardError)\n\t\t\tcase \u003c-time.After(3 * time.Second):\n\t\t\t\tlog.Printf(\"NO forward err...\")\n\t\t\t}\n\t\t}\n\t}()\n}\n```\n\n## \u003ca name=\"inspiration\"\u003e\u003c/a\u003eInspiration\n- [ssh via bastion](https://stackoverflow.com/questions/35906991/go-x-crypto-ssh-how-to-establish-ssh-connection-to-private-instance-over-a-ba)\n- [Go Best Practices](https://talks.golang.org/2013/bestpractices.slide#29) \n- [Shutdown go listeners](http://zhen.org/blog/graceful-shutdown-of-go-net-dot-listeners/)\n- [sshego](https://github.com/glycerine/sshego)\n\n## \u003ca name=\"release\"\u003e\u003c/a\u003eRelease\n```sh\n$ VERSION=vX.Y.Z make release\n# EXAMPLE:\n$ VERSION=v0.11.3 make release\n```\n\n## \u003ca name=\"license\"\u003e\u003c/a\u003eLicense\n    Copyright (c) 2018-2021 Manuel Vogel\n    Source code is open source and released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmavogel%2Fgo-ssh-forward","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmavogel%2Fgo-ssh-forward","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmavogel%2Fgo-ssh-forward/lists"}