1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package agent_test
- import (
- "log"
- "net"
- "os"
- "golang.org/x/crypto/ssh"
- "golang.org/x/crypto/ssh/agent"
- )
- func ExampleClientAgent() {
-
- socket := os.Getenv("SSH_AUTH_SOCK")
- conn, err := net.Dial("unix", socket)
- if err != nil {
- log.Fatalf("net.Dial: %v", err)
- }
- agentClient := agent.NewClient(conn)
- config := &ssh.ClientConfig{
- User: "username",
- Auth: []ssh.AuthMethod{
-
-
-
- ssh.PublicKeysCallback(agentClient.Signers),
- },
- HostKeyCallback: ssh.InsecureIgnoreHostKey(),
- }
- sshc, err := ssh.Dial("tcp", "localhost:22", config)
- if err != nil {
- log.Fatalf("Dial: %v", err)
- }
-
- sshc.Close()
- }
|