melbahja / goph

🤘 The native golang ssh client to execute your commands over ssh connection. 🚀🚀

Home Page:http://git.io/bfpiw

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support SSH Agent

dixonwille opened this issue · comments

funny enough I had an internal package to a project that did most of this already. But one thing I do not see under auth is the agent. Now I know it works for Linux and Mac but unsure about Windows... For this you may need a auth_unix.go file for this to exist in so that the package still builds for other platforms just without this method.

The following function returns an ssh.AuthMethod that you use as well.

func useAgent() ssh.AuthMethod {
	sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		log.Println(fmt.Errorf("could not find ssh agent: %w", err))
		return nil
	}
	return ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)
}

I can open a PR if you want, just want to know if adding a unix only method is ideal for your package.

You are welcome to open a PR if you have time, if not I will added it tomorrow :).
Thank you for your helpful feedback ❤️.