sshagent

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 3 Imported by: 0

README

sshagent

Go Report Card GoDoc codecov

This package provides an OS independent way to connect to a running "ssh-agent" process which returns an sshagent.*Agent that is a wrapper for [golang.org/x/crypto/ssh/agent.ExtendedAgent].

On Windows, named pipes are used to connect to a local "ssh-agent", while on other platforms the "SSH_AUTH_SOCK" environment variable is expected to contain the path to a unix socket in order to communicate with the running "ssh-agent".

Example

package main

import (
	"fmt"
    "os"

	"github.com/andrewheberle/sshagent"
)

func main() {
	client, err := sshagent.NewAgent()
	if err != nil {
		fmt.Printf("error connecting to agent")
        os.Exit(1)
	}

	if _, err := client.List(); err != nil {
		fmt.Printf("error listing keys from agent")
	}
}

Documentation

Overview

The sshagent package provides an OS independent way to connect to a running "ssh-agent" process which returns an *Agent that is a wrapper for agent.ExtendedAgent.

On Windows, named pipes are used to connect to a local "ssh-agent", while on other platforms the "SSH_AUTH_SOCK" environment variable is expected to contain the path to a unix socket in order to communicate with the running "ssh-agent".

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	agent.ExtendedAgent
}

Agent wraps agent.ExtendedAgent

func NewAgent

func NewAgent() (*Agent, error)

NewAgent connects to a local SSH agent either via unix socket or named pipes depending on the OS

In the case of a non-Windows OS, the "SSH_AUTH_SOCK" environment variable must be set or the process will fail.

On Windows a connection is attempted to "\\.\pipe\openssh-ssh-agent" which is the default named pipe path for the native OpenSSH Authentication Agent.

Example

This example shows connecting to an existing agent and listing all identities from it.

This will fail unless a local SSH agent is running

package main

import (
	"fmt"

	"github.com/andrewheberle/sshagent"
)

func main() {
	client, err := sshagent.NewAgent()
	if err != nil {
		fmt.Printf("error connecting to agent")

		return
	}

	if _, err := client.List(); err != nil {
		fmt.Printf("error listing keys from agent")
	}
}
Output:

error connecting to agent

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL