func tryAgentConnect(user, addr string) (client *ssh.Client) { if auth, ok := getAgentAuth(); ok { config := &ssh.ClientConfig{ User: user, Auth: []ssh.AuthMethod{auth}, } client, _ = ssh.Dial("tcp", addr, config) } return }
func sshConnect(user, addr, keypath string) (client *ssh.Client) { // try connecting via agent first client = tryAgentConnect(user, addr) if client != nil { return } // if that failed try with the key and password methods auths := make([]ssh.AuthMethod, 0, 2) auths = addKeyAuth(auths, keypath) auths = addPasswordAuth(user, addr, auths) config := &ssh.ClientConfig{ User: user, Auth: auths, } client, err := ssh.Dial("tcp", addr, config) if err != nil { log.Print(err) os.Exit(1) } return }