# README
sshc

sshc.NewClient()
returns *ssh.Client
using ssh_config(5)
Usage
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/v2"
)
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
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
) - Knownhosts ( Default is empty )
- Password
Supported ssh_config keywords
- Hostname
- Port
- User
- IdentityFile
- ProxyCommand
- ProxyJump
References
# Packages
Package sshc provides sshc.NewClient() that returns *ssh.Client using ssh_config(5).