authorized_keys_d

package
v0.36.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

authorized_keys_d manages a user's ~/.ssh/authorized_keys.d and can produce a ~/.ssh/authorized_keys file from the authorized_keys.d contents.

Index

Constants

View Source
const (
	AuthorizedKeysFile = "authorized_keys"
	AuthorizedKeysDir  = "authorized_keys.d"
	PreservedKeysName  = "orig_authorized_keys"
	SSHDir             = ".ssh"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SSHAuthorizedKey

type SSHAuthorizedKey struct {
	Name     string // Name given to the key.
	Disabled bool   // Disabled state of the key.
	Path     string // Path to the file backing the key.
	// contains filtered or unexported fields
}

SSHAuthorizedKey represents an opened user's authorized_keys.d/<name> entry.

func (*SSHAuthorizedKey) Disable

func (ak *SSHAuthorizedKey) Disable() error

Disable disables the opened key.

func (*SSHAuthorizedKey) Remove

func (ak *SSHAuthorizedKey) Remove() error

Remove removes the opened key.

func (*SSHAuthorizedKey) Replace

func (ak *SSHAuthorizedKey) Replace(keys []byte) error

Replace replaces the opened key with the supplied data.

type SSHAuthorizedKeysDir

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

SSHAuthorizedKeysDir represents an opened user's authorized_keys.d.

func Open

func Open(usr *user.User, create bool) (*SSHAuthorizedKeysDir, error)

Open opens the authorized keys directory for the supplied user. If create is false, Open will fail if no directory exists yet. If create is true, Open will create the directory if it doesn't exist, preserving the authorized_keys file in the process. After a successful open, Close should be called when finished to unlock the directory.

func (*SSHAuthorizedKeysDir) Add

func (akd *SSHAuthorizedKeysDir) Add(name string, keys []byte, replace, force bool) error

Add adds the supplied key at name. replace enables replacing keys already existing at name. force enables adding keys to a disabled name, enabling it in the process. Names starting wtih ".", and anything containing "/" are disallowed.

func (*SSHAuthorizedKeysDir) Close

func (akd *SSHAuthorizedKeysDir) Close() error

Close closes the authorized keys directory.

func (*SSHAuthorizedKeysDir) Disable

func (akd *SSHAuthorizedKeysDir) Disable(name string) error

Disable disables the key at name.

func (*SSHAuthorizedKeysDir) KeysDirPath

func (akd *SSHAuthorizedKeysDir) KeysDirPath() string

KeysDirPath returns the authorized_keys.d directory path for this SSHAuthorizedKeysDir. This is the directory containing the discrete key files.

func (*SSHAuthorizedKeysDir) KeysFilePath

func (akd *SSHAuthorizedKeysDir) KeysFilePath() string

KeysFilePath returns the backing authorized_keys file path for this SSHAuthorizedKeysDir. This is the file written to by Sync().

func (*SSHAuthorizedKeysDir) Open

func (akd *SSHAuthorizedKeysDir) Open(name string) (*SSHAuthorizedKey, error)

Open opens the key at name.

func (*SSHAuthorizedKeysDir) Remove

func (akd *SSHAuthorizedKeysDir) Remove(name string) error

Remove removes the key at name.

func (*SSHAuthorizedKeysDir) Sync

func (akd *SSHAuthorizedKeysDir) Sync() error

Sync synchronizes the user's ~/.ssh/authorized_keys file with the current authorized_keys.d directory state.

func (*SSHAuthorizedKeysDir) WalkKeys

func (akd *SSHAuthorizedKeysDir) WalkKeys(f func(*SSHAuthorizedKey) error) error

WalkKeys iterates across all keys in akd, calling f for each key. Iterating stops on error, and the error is propagated out.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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