Skip to content

kbolino/pageant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Pageant client

This repository contains a library for Go that provides a native PuTTY Pageant SSH agent implementation compatible with the golang.org/x/crypto/ssh/agent package.

This package, rather unsuprisingly, only works with Windows. See below for alternatives on Unix/Linux platforms.

Usage

import (
	"golang.org/x/crypto/ssh"
	"golang.org/x/crypto/ssh/agent"
	"github.com/kbolino/pageant"
)

func main() {
	agentConn, err := pageant.NewConn()
	if err != nil {
		// failed to connect to Pageant
	}
	defer agentConn.Close()
	sshAgent := agent.NewClient(agentConn)
	signers, err := sshAgent.Signers()
	if err != nil {
		// failed to get signers from Pageant
	}
	config := ssh.ClientConfig{
		Auth:            []ssh.AuthMethod{ssh.PublicKeys(signers...)},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
		User:            "somebody",
	}
	sshConn, err := ssh.Dial("tcp", "someserver:22", &config)
	if err != nil {
		// failed to connect to SSH
	}
	defer sshConn.Close()
	// now connected to SSH with public key auth from Pageant
	// ...
}

Unix/Linux Alternatives

The ssh-agent command implements the same SSH agent protocol as Pageant, but over a Unix domain socket instead of shared memory. The path to this socket is exposed through the environment variable SSH_AUTH_SOCK.

Replace the connection to Pageant with one to the socket:

	// instead of this:
	agentConn, err := pageant.NewConn()
	// do this:
	agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))

Testing

The standard tests require Pageant to be running and to have at least 1 key loaded. To test connecting to an SSH server, set the sshtest build flag and see the comments in pageant_ssh_test.go for how to set up the test.

About

Go native Pageant client implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages