ssh/agent: fix example

Since there is no ClientAgent identifier, ExampleClientAgent wasn't
displayed as an example by godoc.

Change-Id: Ied8df7d8412c4aa483d42315986af49ba8fdbcef
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/208480
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Filippo Valsorda
2019-11-22 22:04:53 +00:00
parent 4f8c1d86b1
commit ac88ee75c9
+9 -9
View File
@@ -13,20 +13,20 @@ import (
"golang.org/x/crypto/ssh/agent"
)
func ExampleClientAgent() {
// ssh-agent has a UNIX socket under $SSH_AUTH_SOCK
func ExampleNewClient() {
// ssh-agent(1) provides a UNIX socket at $SSH_AUTH_SOCK.
socket := os.Getenv("SSH_AUTH_SOCK")
conn, err := net.Dial("unix", socket)
if err != nil {
log.Fatalf("net.Dial: %v", err)
log.Fatalf("Failed to open SSH_AUTH_SOCK: %v", err)
}
agentClient := agent.NewClient(conn)
config := &ssh.ClientConfig{
User: "username",
User: "gopher",
Auth: []ssh.AuthMethod{
// Use a callback rather than PublicKeys
// so we only consult the agent once the remote server
// wants it.
// Use a callback rather than PublicKeys so we only consult the
// agent once the remote server wants it.
ssh.PublicKeysCallback(agentClient.Signers),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
@@ -34,8 +34,8 @@ func ExampleClientAgent() {
sshc, err := ssh.Dial("tcp", "localhost:22", config)
if err != nil {
log.Fatalf("Dial: %v", err)
log.Fatal(err)
}
// .. use sshc
// Use sshc...
sshc.Close()
}