ssh

package
v0.0.0-...-57dcc05 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCommonUserPublicKeys

func GetCommonUserPublicKeys(
	ctx context.Context,
	fileSystem fs.FS,
) ([]string, error)

GetCommonUserPublicKeys is responsible for attempting to load common public key files from the supplied file system. See LocalUserSSHFileSystem for accessing the users ssh file system.

The files target by this function are: - id_ed25519.pub - id_ecdsa.pub - id_rsa.pub - identity.pub

No attempt is made to verify the contents of each file is a valid ssh public key. Access errors to files such as permission or not found are ignored. Any other read based errors are returned.

func GetFileSystemPublicKeys

func GetFileSystemPublicKeys(
	ctx context.Context,
	fileSystem fs.FS,
) ([]string, error)

GetFileSystemPublicKeys will attempt to find all ssh public keys at the root of the file system and read them all into a slice of public ssh keys. No attempt is made to assert if a file contains a valid public key.

Public keys are found based on the file in the file system ending in a ".pub" suffix. If a file is read and a permission error or file not found error occurs this function will simply move on and not report the problem upwards. This is a best effort approach.

This function is useful for reading the public keys found in a users juju ssh directory. See github.com/juju/juju/juju/osenv.JujuXDGDataSSHFS.

func LocalUserSSHFileSystem

func LocalUserSSHFileSystem() fs.FS

LocalUserSSHFileSystem returns a file system rooted at the local users .ssh directory.

func MakeAuthorizedKeysString

func MakeAuthorizedKeysString(keys []string) string

MakeAuthorizedKeysString is responsible for turning a slice of public ssh keys into a compliant authorized key file string. Keys are written in the order they are defined in the keys slice.

No validation is performed on the keys to make sure they are public ssh keys.

func SplitAuthorizedKeys

func SplitAuthorizedKeys(keyData string) ([]string, error)

SplitAuthorizedKeys extracts a key slice from the specified key data, by splitting the key data into lines and ignoring comments and blank lines.

No validation is performed on the split keys to make sure they are compliant.

func SplitAuthorizedKeysByDelimiter

func SplitAuthorizedKeysByDelimiter(delimiter byte, keyData string) ([]string, error)

SplitAuthorizedKeysByDelimiter extracts a key slice from the specified key data, by splitting the key data into lines separated by delimiter and ignoring comments and blank lines.

No validation is performed on the split keys to make sure they are compliant.

func SplitAuthorizedKeysReader

func SplitAuthorizedKeysReader(reader io.Reader) ([]string, error)

SplitAuthorizedKeysReaderByDelimiter is responsible for splitting up all of the authorized keys contained within the reader into a slice of keys.

Keys in the reader are parsed in accordance with the open ssh authorized_keys file format.

Any errors encountered when reading from the reader are returned to the caller with exception of io.EOF.

No validation is performed on the split keys to make sure they are compliant.

func SplitAuthorizedKeysReaderByDelimiter

func SplitAuthorizedKeysReaderByDelimiter(
	delimiter byte,
	reader io.Reader,
) ([]string, error)

SplitAuthorizedKeysReaderByDelimiter is responsible for splitting up all of the authorized keys contained within the reader into a slice of keys. The delimiter tells the parser what to use when considering a newline.

Keys in the reader are parsed in accordance with the open ssh authorized_keys file format.

Any errors encountered when reading from the reader are returned to the caller with exception of io.EOF.

No validation is performed on the split keys to make sure they are compliant.

func WriteAuthorizedKeys

func WriteAuthorizedKeys(writer io.Writer, keys []string)

WriteAuthorizedKeys is responsible for writing a slice of authorized ssh public keys to a write as a standards compliant authorized keys file. Keys are written in the order they are defined in the keys slice.

No validation is performed on the keys to make sure they are public ssh keys.

Types

type PublicKey

type PublicKey struct {
	// Key holds the parse key data for the public key.
	Key ssh.PublicKey

	// Comment is the comment string attached to the authorised key.
	Comment string
}

PublicKey represents a single authorised key line that would commonly be found in a authorized_keys file. http://man.he.net/man5/authorized_keys

func ParsePublicKey

func ParsePublicKey(key string) (PublicKey, error)

ParsePublicKey parses a single line from an authorised keys file returning a PublicKey representation of the data. ssh.ParseAuthorizedKey is used to perform the underlying validating and parsing.

func (*PublicKey) Fingerprint

func (a *PublicKey) Fingerprint() string

Fingerprint returns the SHA256 fingerprint of the public key.

Directories

Path Synopsis
Package importer provides a means for importing public ssh keys from a well known internet based location such as Github or Launchpad.
Package importer provides a means for importing public ssh keys from a well known internet based location such as Github or Launchpad.

Jump to

Keyboard shortcuts

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