1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/crypto/ssh"
13 "golang.org/x/crypto/ssh/agent"
16 func ExampleClientAgent() {
17 // ssh-agent has a UNIX socket under $SSH_AUTH_SOCK
18 socket := os.Getenv("SSH_AUTH_SOCK")
19 conn, err := net.Dial("unix", socket)
21 log.Fatalf("net.Dial: %v", err)
23 agentClient := agent.NewClient(conn)
24 config := &ssh.ClientConfig{
26 Auth: []ssh.AuthMethod{
27 // Use a callback rather than PublicKeys
28 // so we only consult the agent once the remote server
30 ssh.PublicKeysCallback(agentClient.Signers),
32 HostKeyCallback: ssh.InsecureIgnoreHostKey(),
35 sshc, err := ssh.Dial("tcp", "localhost:22", config)
37 log.Fatalf("Dial: %v", err)