https://github.com/k1low/sshc
sshc.NewClient() returns *ssh.Client using ssh_config(5)
https://github.com/k1low/sshc
ssh-client ssh-config
Last synced: about 1 year ago
JSON representation
sshc.NewClient() returns *ssh.Client using ssh_config(5)
- Host: GitHub
- URL: https://github.com/k1low/sshc
- Owner: k1LoW
- License: mit
- Created: 2018-12-02T13:45:37.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-12-11T23:32:35.000Z (over 1 year ago)
- Last Synced: 2025-03-29T05:41:34.663Z (about 1 year ago)
- Topics: ssh-client, ssh-config
- Language: Go
- Homepage:
- Size: 150 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sshc [](https://github.com/k1LoW/sshc/actions) [](https://pkg.go.dev/github.com/k1LoW/sshc/v4)  
`sshc.NewClient()` returns `*ssh.Client` using [ssh_config(5)](https://linux.die.net/man/5/ssh_config)
## Usage
Describe `~/.ssh/config`.
```
Host myhost
HostName 203.0.113.1
User k1low
Port 10022
IdentityFile ~/.ssh/myhost_rsa
```
Use `sshc.NewClient()` as follows
``` go
package main
import (
"bytes"
"log"
"github.com/k1LoW/sshc/v4"
)
func main() {
client, err := sshc.NewClient("myhost")
if err != nil {
log.Fatalf("error: %v", err)
}
session, err := client.NewSession()
if err != nil {
log.Fatalf("error: %v", err)
}
defer session.Close()
var stdout = &bytes.Buffer{}
session.Stdout = stdout
err = session.Run("hostname")
if err != nil {
log.Fatalf("error: %v", err)
}
log.Printf("result: %s", stdout.String())
}
```
### sshc.Option
``` go
client, err := sshc.NewClient("myhost", User("k1low"), Port(1022))
```
See [godoc page](https://pkg.go.dev/github.com/k1LoW/sshc/v4#Option)
## Supported ssh_config keywords
- Hostname
- Port
- User
- IdentityFile
- ProxyCommand
- ProxyJump
## References
- https://github.com/kevinburke/ssh_config