github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/crypto/ssh/agent/example_test.go (about) 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 "net" 10 "os" 11 12 "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/ssh" 13 "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/ssh/agent" 14 ) 15 16 func ExampleNewClient() { 17 // ssh-agent(1) provides a UNIX socket at $SSH_AUTH_SOCK. 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 // Use a callback rather than PublicKeys so we only consult the 29 // agent once the remote server wants it. 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 // Use sshc... 40 sshc.Close() 41 }