https://github.com/metrue/go-ssh-client
A handy ssh client
https://github.com/metrue/go-ssh-client
golang-ssh ssh ssh-client
Last synced: about 1 month ago
JSON representation
A handy ssh client
- Host: GitHub
- URL: https://github.com/metrue/go-ssh-client
- Owner: metrue
- License: mit
- Created: 2019-07-24T17:03:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-11T21:15:03.000Z (almost 4 years ago)
- Last Synced: 2025-03-17T22:17:33.671Z (about 2 months ago)
- Topics: golang-ssh, ssh, ssh-client
- Language: Go
- Size: 25.4 KB
- Stars: 23
- Watchers: 3
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-ssh-client
This is a little pacakge helps you run command on remote host via SSH

[](https://goreportcard.com/report/github.com/metrue/go-ssh-client)
[](http://godoc.org/github.com/metrue/go-ssh-client)
[](https://asciinema.org/a/WYvZVCSiAu6FuUksQuhTITIOU)```go
package mainimport (
"log"
"os"ssh "github.com/metrue/go-ssh-client"
)func main() {
host := "127.0.0.1"
script := `
x=1
while [ $x -le 5 ]; do
echo 'hello'
x=$(( $x + 1 ))
sleep 1
done
`
err := ssh.New(host).
WithUser("root").
WithKey("/your/path/to/id_ras"). // Default is ~/.ssh/id_rsa
WithPort("2222"). // Default is 22
RunCommand(script, ssh.CommandOptions{
Stdout: os.Stdout,
Stderr: os.Stderr,
Stdin: os.Stdin,
})
if err != nil {
log.Fatal(err)
}
}
```## Test
```
$ make start_ssh_server
$ make test
$ make clean #clean up running Docker container
```