{"id":34235764,"url":"https://github.com/bugfan/gossh","last_synced_at":"2026-03-13T15:30:41.407Z","repository":{"id":57659281,"uuid":"473484122","full_name":"bugfan/gossh","owner":"bugfan","description":"ssh client for golang","archived":false,"fork":false,"pushed_at":"2022-03-24T10:04:00.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-19T08:40:27.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bugfan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-24T06:31:42.000Z","updated_at":"2022-03-24T06:40:51.000Z","dependencies_parsed_at":"2022-09-08T00:10:23.252Z","dependency_job_id":null,"html_url":"https://github.com/bugfan/gossh","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bugfan/gossh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugfan%2Fgossh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugfan%2Fgossh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugfan%2Fgossh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugfan%2Fgossh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugfan","download_url":"https://codeload.github.com/bugfan/gossh/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugfan%2Fgossh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30469312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2025-12-16T02:25:52.910Z","updated_at":"2026-03-13T15:30:41.398Z","avatar_url":"https://github.com/bugfan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\t\u003ch1\u003eGolang SSH Client.\u003c/h1\u003e\n\t\u003ca href=\"https://github.com/bugfan/gossh\"\u003egossh\u003c/a\u003e\n\t\u003ch4 align=\"center\"\u003e\n\t\tFast and easy golang ssh client module.\n\t\u003c/h4\u003e\n\t\u003cp\u003eGoph is a lightweight Go SSH client focusing on simplicity!\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e ❘\n\t\u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e ❘\n\t\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e ❘\n\t\u003ca href=\"#examples\"\u003eExamples\u003c/a\u003e ❘\n\u003c/p\u003e\n\n\n## 🚀\u0026nbsp; Installation\n\n```bash\ngo get github.com/bugfan/gossh\n```\n\n## 🤘\u0026nbsp; Features\n\n- Easy to use and **simple API**.\n- Supports **known hosts** by default.\n- Supports connections with **passwords**.\n- Supports connections with **private keys**.\n- Supports connections with **protected private keys** with passphrase.\n- Supports **upload** files from local to remote.\n- Supports **download** files from remote to local.\n- Supports connections with **ssh agent** (Unix systems only).\n- Supports adding new hosts to **known_hosts file**.\n- Supports **file system operations** like: `Open, Create, Chmod...`\n- Supports **context.Context** for command cancellation.\n\n## 📄\u0026nbsp; Usage\n\nRun a command via ssh:\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"fmt\"\n\t\"github.com/bugfan/gossh\"\n)\n\nfunc main() {\n\n\t// Start new ssh connection with private key.\n\tauth, err := gossh.Key(\"/home/yourname/.ssh/id_rsa\", \"\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tclient, err := gossh.New(\"root\", \"192.1.1.3\",22, auth)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Defer closing the network connection.\n\tdefer client.Close()\n\n\t// Execute your command.\n\tout, err := client.Run(\"ls /tmp/\")\n\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Get your output as []byte.\n\tfmt.Println(string(out))\n}\n```\n\n#### 🔐 Start Connection With Protected Private Key:\n```go\nauth, err := gossh.Key(\"/home/yourname/.ssh/id_rsa\", \"you_passphrase_here\")\nif err != nil {\n\t// handle error\n}\n\nclient, err := gossh.New(\"root\", \"192.1.1.3\",22, auth)\n```\n\n#### 🔑 Start Connection With Password:\n```go\nclient, err := gossh.New(\"root\", \"192.1.1.3\",22, gossh.Password(\"you_password_here\"))\n```\n\n#### ☛ Start Connection With SSH Agent (Unix systems only):\n```go\nauth, err := gossh.UseAgent()\nif err != nil {\n\t// handle error\n}\n\nclient, err := gossh.New(\"root\", \"192.1.1.3\",22, auth)\n```\n\n#### ⤴️ Upload Local File to Remote:\n```go\nerr := client.Upload(\"/path/to/local/file\", \"/path/to/remote/file\")\n```\n\n#### ⤵️ Download Remote File to Local:\n```go\nerr := client.Download(\"/path/to/remote/file\", \"/path/to/local/file\")\n```\n\n#### ☛ Execute Bash Commands:\n```go\nout, err := client.Run(\"bash -c 'printenv'\")\n```\n\n#### ☛ Execute Bash Command with timeout:\n```go\ncontext, cancel := context.WithTimeout(ctx, time.Second)\ndefer cancel()\n// will send SIGINT and return error after 1 second\nout, err := client.RunContext(ctx, \"sleep 5\")\n```\n\n#### ☛ Execute Bash Command With Env Variables:\n```go\nout, err := client.Run(`env MYVAR=\"MY VALUE\" bash -c 'echo $MYVAR;'`)\n```\n\n#### 🥪 Using Goph Cmd:\n\n`gossh.Cmd` struct is like the Go standard `os/exec.Cmd`.\n\n```go\n// Get new `gossh.Cmd`\ncmd, err := client.Command(\"ls\", \"-alh\", \"/tmp\")\n\n// or with context:\n// cmd, err := client.CommandContext(ctx, \"ls\", \"-alh\", \"/tmp\")\n\nif err != nil {\n\t// handle the error!\n}\n\n// You can set env vars, but the server must be configured to `AcceptEnv line`.\ncmd.Env = []string{\"MY_VAR=MYVALUE\"}\n\n// Run you command.\nerr = cmd.Run()\n```\n\n🗒️ Just like `os/exec.Cmd` you can run `CombinedOutput, Output, Start, Wait`, and [`ssh.Session`](https://pkg.go.dev/golang.org/x/crypto/ssh#Session) methods like `Signal`...\n\n#### 📂 File System Operations Via SFTP:\n\nYou can easily get a [SFTP](https://github.com/pkg/sftp) client from Goph client:\n```go\n\nsftp, err := client.NewSftp()\n\nif err != nil {\n\t// handle the error!\n}\n\nfile, err := sftp.Create(\"/tmp/remote_file\")\n\nfile.Write([]byte(`Hello world`))\nfile.Close()\n\n```\n🗒️ For more file operations see [SFTP Docs](https://github.com/pkg/sftp).\n\n\n## 🤝\u0026nbsp; Missing a Feature?\n\nFeel free to open a new issue, or contact me.\n\n## Reference\n- See https://github.com/melbahja/goph\n- Case It is difficult to specify custom ports,So I Modify them and generate this one!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugfan%2Fgossh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugfan%2Fgossh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugfan%2Fgossh/lists"}