| 1 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris |
| 2 | |
| 3 | package sshutil |
| 4 | |
| 5 | import ( |
| 6 | "net" |
| 7 | "os" |
| 8 | |
| 9 | "github.com/pkg/errors" |
| 10 | "golang.org/x/crypto/ssh/agent" |
| 11 | ) |
| 12 | |
| 13 | // dialAgent returns an ssh.Agent client. It uses the SSH_AUTH_SOCK to connect |
| 14 | // to the agent. |
| 15 | func dialAgent() (*Agent, error) { |
| 16 | socket := os.Getenv("SSH_AUTH_SOCK") |
| 17 | conn, err := net.Dial("unix", socket) |
| 18 | if err != nil { |
| 19 | return nil, errors.Wrap(err, "error connecting with ssh-agent") |
| 20 | } |
| 21 | return &Agent{ |
| 22 | ExtendedAgent: agent.NewClient(conn), |
| 23 | Conn: conn, |
| 24 | }, nil |
| 25 | } |