...
1
2
3
4
5 package agent_test
6
7 import (
8 "log"
9 "net"
10 "os"
11
12 "golang.org/x/crypto/ssh"
13 "golang.org/x/crypto/ssh/agent"
14 )
15
16 func ExampleNewClient() {
17
18 socket := os.Getenv("SSH_AUTH_SOCK")
19 conn, err := net.Dial("unix", socket)
20 if err != nil {
21 log.Fatalf("Failed to open SSH_AUTH_SOCK: %v", err)
22 }
23
24 agentClient := agent.NewClient(conn)
25 config := &ssh.ClientConfig{
26 User: "gopher",
27 Auth: []ssh.AuthMethod{
28
29
30 ssh.PublicKeysCallback(agentClient.Signers),
31 },
32 HostKeyCallback: ssh.InsecureIgnoreHostKey(),
33 }
34
35 sshc, err := ssh.Dial("tcp", "localhost:22", config)
36 if err != nil {
37 log.Fatal(err)
38 }
39
40 sshc.Close()
41 }
42
View as plain text