sshc.NewClient()
returns *ssh.Client
using ssh_config(5)
Describe ~/.ssh/config
.
Host myhost
HostName 203.0.113.1
User k1low
Port 10022
IdentityFile ~/.ssh/myhost_rsa
Use sshc.NewClient()
as follows
package main
import (
"bytes"
"log"
"github.com/k1LoW/sshc"
)
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())
}
client, err := sshc.NewClient("myhost", User("k1low"), Port(1022))
Available options
- User
- Port
- Passphrase
- ConfigPath ( Default is
~/.ssh/config
and/etc/ssh/ssh_config
) - UseAgent ( Default is
true
)