fix agent and default private key issue

master
fangdingjun 8 years ago
parent 36d4f908be
commit a3c1a3ee75

@ -131,6 +131,7 @@ func main() {
if pass == "" && key == "" { if pass == "" && key == "" {
var pkeys []ssh.Signer var pkeys []ssh.Signer
// read default ssh private
home := os.Getenv("HOME") home := os.Getenv("HOME")
for _, f := range []string{ for _, f := range []string{
".ssh/id_rsa", ".ssh/id_rsa",
@ -149,20 +150,28 @@ func main() {
} }
} }
if len(pkeys) != 0 { // auth with agent
obfssh.Log(obfssh.DEBUG, "private key length %d", len(pkeys))
auth = append(auth, ssh.PublicKeys(pkeys...))
}
agentConn, err = net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")) agentConn, err = net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
if err == nil { if err == nil {
defer agentConn.Close() defer agentConn.Close()
obfssh.Log(obfssh.DEBUG, "add auth method with agent %s", os.Getenv("SSH_AUTH_SOCK")) obfssh.Log(obfssh.DEBUG, "add auth method with agent %s", os.Getenv("SSH_AUTH_SOCK"))
agentClient := agent.NewClient(agentConn) agentClient := agent.NewClient(agentConn)
auth = append(auth, ssh.PublicKeysCallback(agentClient.Signers)) //auth = append(auth, ssh.PublicKeysCallback(agentClient.Signers))
signers, err := agentClient.Signers()
if err == nil {
pkeys = append(pkeys, signers...)
} else {
obfssh.Log(obfssh.DEBUG, "get key from agent failed: %s", err)
}
} else { } else {
obfssh.Log(obfssh.DEBUG, "connect to agent failed") obfssh.Log(obfssh.DEBUG, "connect to agent failed")
} }
if len(pkeys) != 0 {
obfssh.Log(obfssh.DEBUG, "private key length %d", len(pkeys))
auth = append(auth, ssh.PublicKeys(pkeys...))
}
} }
args := flag.Args() args := flag.Args()

Loading…
Cancel
Save