-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh-agent_unix.go
45 lines (38 loc) · 931 Bytes
/
ssh-agent_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//go:build !windows
// +build !windows
package main
import (
"log"
"net"
"golang.org/x/crypto/ssh/agent"
)
func ServeSSHAgentOnUnixDomainSocket(path string) error {
// Start a ssh agent on unix domain socket
listener, err := net.Listen("unix", path)
if err != nil {
return err
}
defer listener.Close()
log.Println("SSH agent started at ", path)
for {
conn, err := listener.Accept()
if err != nil {
return err
}
go func() {
// Handle the connection
err := agent.ServeAgent(myAgent, conn)
log.Println("Agent conn closed:", err)
}()
}
}
func RunSSHServer() {
log.Println(`=== Set the following environment variable before using ssh ===
export SSH_AUTH_SOCK=/tmp/44ssh
============================================================`)
// Start a ssh agent on unix domain socket
err := ServeSSHAgentOnUnixDomainSocket(`/tmp/44ssh`)
if err != nil {
log.Fatal("ListenUnix failed:", err)
}
}