Skip to content

Commit 7e33b4e

Browse files
authored
Merge pull request #1388 from romanZupancic/windows-sshagent-env
Add SSH_AUTH_SOCK support to Windows environments.
2 parents e941cbd + 4c51516 commit 7e33b4e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

internal/sshutil/agent_windows.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@ import (
1313
// dialAgent returns an ssh.Agent client. It uses the SSH_AUTH_SOCK to connect
1414
// to the agent.
1515
func dialAgent() (*Agent, error) {
16-
// Attempt unix sockets for environments like cygwin.
16+
// Override the default windows openssh-ssh-agent pipe
1717
if socket := os.Getenv("SSH_AUTH_SOCK"); socket != "" {
18+
// Attempt unix sockets for environments like cygwin.
1819
if conn, err := net.Dial("unix", socket); err == nil {
1920
return &Agent{
2021
ExtendedAgent: agent.NewClient(conn),
2122
Conn: conn,
2223
}, nil
2324
}
25+
26+
// Connect to Windows pipe at the supplied address
27+
conn, err := winio.DialPipeContext(context.Background(), socket)
28+
if err != nil {
29+
return nil, errors.Wrap(err, "error connecting with ssh-agent at pipe specified by environment variable SSH_AUTH_SOCK")
30+
}
31+
return &Agent{
32+
ExtendedAgent: agent.NewClient(conn),
33+
Conn: conn,
34+
}, nil
2435
}
2536

26-
// Windows OpenSSH agent
37+
// DEFAULT: Windows OpenSSH agent
2738
conn, err := winio.DialPipeContext(context.Background(), `\\.\\pipe\\openssh-ssh-agent`)
2839
if err != nil {
2940
return nil, errors.Wrap(err, "error connecting with ssh-agent")

0 commit comments

Comments
 (0)