~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/golang.org/x/crypto/ssh/agent/example_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
 
 
5
package agent_test
 
6
 
 
7
import (
 
8
        "log"
 
9
        "os"
 
10
        "net"
 
11
 
 
12
        "golang.org/x/crypto/ssh"
 
13
        "golang.org/x/crypto/ssh/agent"
 
14
)
 
15
 
 
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)
 
20
        if err != nil {
 
21
                log.Fatalf("net.Dial: %v", err)
 
22
        }
 
23
        agentClient := agent.NewClient(conn)
 
24
        config := &ssh.ClientConfig{
 
25
                User: "username",
 
26
                Auth: []ssh.AuthMethod{
 
27
                        // Use a callback rather than PublicKeys
 
28
                        // so we only consult the agent once the remote server
 
29
                        // wants it.
 
30
                        ssh.PublicKeysCallback(agentClient.Signers),
 
31
                },
 
32
        }
 
33
 
 
34
        sshc, err := ssh.Dial("tcp", "localhost:22", config)
 
35
        if err != nil {
 
36
                log.Fatalf("Dial: %v", err)
 
37
        }
 
38
        // .. use sshc
 
39
        sshc.Close()
 
40
}