ssh/agent: fix example
Since there is no ClientAgent identifier, ExampleClientAgent wasn't
displayed as an example by godoc.
@@ -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()
}
