keys

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAuthorizedKeys

func CreateAuthorizedKeys(keys []*Key) string

CreateAuthorizedKeys returns a single string built of a set of keys all separated with a newline (\n). This can be used in SSH authorized_key files.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent is a connection to an SSH agent, along with some supplementray data for manageing the connection.

func NewSSHAgent

func NewSSHAgent(path string, opts ...AgentOpt) (*Agent, error)

NewSSHAgent establishes a connection to a unix socket at the given path representing an SSH agent. Options can be given to configure the connection and how the agent is used. Options are executed in the order provided. Returned is an SSH agent connection or an error if unsuccessful.

func (*Agent) Close

func (a *Agent) Close() error

Close closes the underlying socket connection used to communicate with the SSH agent.

func (*Agent) GetKeys

func (a *Agent) GetKeys() ([]*Key, error)

GetKeys uses the SSH agent connection to retreive all the keys present in the agent in the authorized key format. If the agent is locked and the correct passphrase option has been provided, the agent will be unlocked and re-locked as required. Returned are the keys present in the agent or an error if unsuccessful.

type AgentOpt

type AgentOpt func(*Agent)

AgentOpt is a configuration option for an SSH agent connection.

func AgentPassphraseOpt

func AgentPassphraseOpt(passphrase string) AgentOpt

AgentPassphraseOpt should be provided when creating a new agent if the SSH agent is locked by a passphrase.

type Key

type Key struct {
	// contains filtered or unexported fields
}

Key represents an SSH public key in the authorized_keys format.

func NewKey

func NewKey(raw, name string) (*Key, error)

NewKey returns a new key based on the raw key string and the key name (comment). If the key can not be parsed as a valid authorized key, an error is returned.

func NewKeyFromFile

func NewKeyFromFile(filepath string) (*Key, error)

NewKeyFromFile returns a new key based on the contents of a public key file. If the file can not be opened or the key can not be parsed as a valid authorized key, an error is returned.

func (Key) Fingerprint

func (k Key) Fingerprint() string

Fingerprint returns the SHA256 fingerprint of the key.

func (Key) Name

func (k Key) Name() string

Name returns the name of the key as determined by the key comment.

func (Key) Raw

func (k Key) Raw() string

Raw returns the key in a useable authorized_key format.

func (Key) Type

func (k Key) Type() string

Type returns the type of the SSH key (e.g. ssh-rsa).

Jump to

Keyboard shortcuts

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