{"id":13461381,"url":"https://github.com/melbahja/goph","last_synced_at":"2025-05-14T23:07:26.173Z","repository":{"id":37212906,"uuid":"246402552","full_name":"melbahja/goph","owner":"melbahja","description":"🤘 The native golang ssh client to execute your commands over ssh connection. 🚀🚀","archived":false,"fork":false,"pushed_at":"2024-03-08T10:30:07.000Z","size":106,"stargazers_count":1846,"open_issues_count":38,"forks_count":134,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-04-13T19:50:05.226Z","etag":null,"topics":["downloader","go","golang","golang-module","goph","hacktoberfest","remote-execution","sftp","ssh","ssh-agent","ssh-client","ssh-keys","unix-systems","uploader"],"latest_commit_sha":null,"homepage":"http://git.io/bfpiw","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/melbahja.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":"2020-03-10T20:34:17.000Z","updated_at":"2025-04-09T22:30:17.000Z","dependencies_parsed_at":"2022-07-13T15:29:43.321Z","dependency_job_id":"f57c8202-78b8-4b55-be32-55db291c556b","html_url":"https://github.com/melbahja/goph","commit_stats":{"total_commits":83,"total_committers":13,"mean_commits":6.384615384615385,"dds":"0.20481927710843373","last_synced_commit":"d955155146ed06df49062105dfc6277b1eec7a81"},"previous_names":["melbahja/ssh"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melbahja%2Fgoph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melbahja%2Fgoph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melbahja%2Fgoph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melbahja%2Fgoph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/melbahja","download_url":"https://codeload.github.com/melbahja/goph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243362,"owners_count":22038046,"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":["downloader","go","golang","golang-module","goph","hacktoberfest","remote-execution","sftp","ssh","ssh-agent","ssh-client","ssh-keys","unix-systems","uploader"],"created_at":"2024-07-31T11:00:37.081Z","updated_at":"2025-05-14T23:07:21.165Z","avatar_url":"https://github.com/melbahja.png","language":"Go","funding_links":[],"categories":["Go","hacktoberfest","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"\u003cdiv align=\"center\"\u003e\n\t\u003ch1\u003eGolang SSH Client.\u003c/h1\u003e\n\t\u003ca href=\"https://github.com/melbahja/goph\"\u003e\n\t\t\u003cimg src=\"https://github.com/melbahja/goph/raw/master/.github/goph.png\" width=\"200\"\u003e\n\t\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-and-documentation\"\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\t\u003ca href=\"#-license\"\u003eLicense\u003c/a\u003e\n\u003c/p\u003e\n\n\n## 🚀\u0026nbsp; Installation and Documentation\n\n```bash\ngo get github.com/melbahja/goph\n```\n\nYou can find the docs at [go docs](https://pkg.go.dev/github.com/melbahja/goph).\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/melbahja/goph\"\n)\n\nfunc main() {\n\n\t// Start new ssh connection with private key.\n\tauth, err := goph.Key(\"/home/mohamed/.ssh/id_rsa\", \"\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tclient, err := goph.New(\"root\", \"192.1.1.3\", 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 := goph.Key(\"/home/mohamed/.ssh/id_rsa\", \"you_passphrase_here\")\nif err != nil {\n\t// handle error\n}\n\nclient, err := goph.New(\"root\", \"192.1.1.3\", auth)\n```\n\n#### 🔑 Start Connection With Password:\n```go\nclient, err := goph.New(\"root\", \"192.1.1.3\", goph.Password(\"you_password_here\"))\n```\n\n#### ☛ Start Connection With SSH Agent (Unix systems only):\n```go\nauth, err := goph.UseAgent()\nif err != nil {\n\t// handle error\n}\n\nclient, err := goph.New(\"root\", \"192.1.1.3\", 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`Goph.Cmd` struct is like the Go standard `os/exec.Cmd`.\n\n```go\n// Get new `Goph.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; Examples\n\nSee [Examples](https://github.com/melbahja/ssh/blob/master/examples).\n\n## 🤝\u0026nbsp; Missing a Feature?\n\nFeel free to open a new issue, or contact me.\n\n## 📘\u0026nbsp; License\n\nGoph is provided under the [MIT License](https://github.com/melbahja/goph/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelbahja%2Fgoph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelbahja%2Fgoph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelbahja%2Fgoph/lists"}