myssh

package
v0.0.0-...-d0e6ce9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultKey is the default alias name of SSH key
	DefaultKey = "default"
	// HookName is the name of a hook that is called when present after using a key
	HookName       = "hook"
	DefaultBitSize = 2048
)
View Source
const (
	MaskPrompt = '*'
)

Variables

This section is empty.

Functions

func AliasInteractiveLogin

func AliasInteractiveLogin(sshConfigFile string, promptPass bool) error

func AliasKeyCopy

func AliasKeyCopy(hostCfgPath string, aliases []string) error

func AliasLogin

func AliasLogin(aliasName string, promptPass bool, sshConfigFile string) error

func BackupAll

func BackupAll(backupPath string, env *Environment) error

func BatchExecAlias

func BatchExecAlias(sshConfigPath string, promptPass bool, alias string, cmd ...string) error

func ClusterBatchCmds

func ClusterBatchCmds(hostPattern string, PromptPass bool, login *ServerConfig, cmd ...string) error

batch execution of commands

func ClusterCopy

func ClusterCopy(args []string, PromptPass bool, login *ServerConfig) error

func ClusterKeyCopy

func ClusterKeyCopy(hostPattern string, sshPort int, sshUser string, identityfile string) error

func CopyKey

func CopyKey(connectStr string, port string, keyPath string) bool

func CopySSHKey

func CopySSHKey(connectStr string, port string, env *Environment) error

func CreateSSHKey

func CreateSSHKey(env *Environment) (map[string]*SSHKey, error)
func CreateSSHlink(ctxName string, env *Environment) error

func DeleteSSHKey

func DeleteSSHKey(aliasName string, env *Environment) error

func DisplaySSHKey

func DisplaySSHKey(aliasName string, env *Environment) error
func Displaylogo()

func GetBakDirName

func GetBakDirName(name string) string

GetBakFileName generates a backup dir name by current date and time

func InteractiveSetContext

func InteractiveSetContext(env *Environment) error

func KeyStoreInit

func KeyStoreInit(env *Environment) error

func LoadSSHKeys

func LoadSSHKeys(env *Environment) (map[string]*SSHKey, error)

loads all the SSH keys from key store

func NewKV

func NewKV(key, value string) *ssh_config.KV

func ParseExpr

func ParseExpr(expr string) ([]string, error)

func RenameSSHKey

func RenameSSHKey(aliasName string, newaliasName string, env *Environment) error

func SetContext

func SetContext(cfgName string, env *Environment) error

set current context

func SetSSHKey

func SetSSHKey(aliasName string, env *Environment) (map[string]*SSHKey, error)

Types

type ClusterConfig

type ClusterConfig struct {
	Name        string `yaml:"name"`
	HostPattern string `yaml:"hostPattern"`
}

type Clusters

type Clusters []*ClusterConfig

func AddCluster

func AddCluster() (Clusters, error)

func DeleteClusters

func DeleteClusters(names []string) (Clusters, error)

func (Clusters) FindClusterByName

func (cs Clusters) FindClusterByName(name string) (*ClusterConfig, bool)

find cluster by name

func (Clusters) Len

func (cs Clusters) Len() int

func (Clusters) Less

func (cs Clusters) Less(i, j int) bool

func (Clusters) Swap

func (cs Clusters) Swap(i, j int)

type ClustersConfig

type ClustersConfig struct {
	Default  DefaultClusterConfig `yaml:"default"`
	Clusters Clusters             `yaml:"clusters"`
	// contains filtered or unexported fields
}
var (
	ClustersCfg ClustersConfig
)

func ClustersConfigExample

func ClustersConfigExample(env *Environment) *ClustersConfig

func (*ClustersConfig) ConfigPath

func (cfg *ClustersConfig) ConfigPath() string

func (*ClustersConfig) LoadFrom

func (cfg *ClustersConfig) LoadFrom(filePath string) error

load nodes from yaml file

func (*ClustersConfig) SetConfigPath

func (cfg *ClustersConfig) SetConfigPath(configPath string)

func (*ClustersConfig) WriteTo

func (cfg *ClustersConfig) WriteTo(filePath string) error

write nodes config to yaml file

type Context

type Context struct {
	Name          string `yaml:"name"`
	SSHConfig     string `yaml:"sshconfig"`
	ClusterConfig string `yaml:"clusterCfg"`
}

Context myssh context

type Contexts

type Contexts []Context

Contexts myssh contexts

func AddConfig

func AddConfig(env *Environment) (Contexts, error)

func DeleteConfig

func DeleteConfig(cfgs []string, env *Environment) (Contexts, error)

delete context

func (Contexts) FindContextByName

func (cs Contexts) FindContextByName(name string) (Context, bool)

find context by name

func (Contexts) Len

func (cs Contexts) Len() int

func (Contexts) Less

func (cs Contexts) Less(i, j int) bool

func (Contexts) Swap

func (cs Contexts) Swap(i, j int)

type DefaultClusterConfig

type DefaultClusterConfig struct {
	User                string        `yaml:"user"`
	PrivateKey          string        `yaml:"privateKey"`
	Port                int           `yaml:"port"`
	ServerAliveInterval time.Duration `yaml:"server_alive_interval"`
}

type Environment

type Environment struct {
	StorePath string
	SSHPath   string
	SKMPath   string
}

type HostConfig

type HostConfig struct {
	// Alias alias
	Alias string
	// Path found in which file
	Path string
	// PathMap key is file path, value is the alias's hosts
	PathMap map[string][]*ssh_config.Host
	// OwnConfig own config
	OwnConfig map[string]string
	// ImplicitConfig implicit config
	ImplicitConfig map[string]string
}

HostConfig struct include alias, connect string and other config

func AddHostAlias

func AddHostAlias(hostCfgPath string) ([]*HostConfig, error)

func DeleteAliases

func DeleteAliases(p string, aliases ...string) ([]*HostConfig, error)

func ListAlias

func ListAlias(p string, lo ListOption) ([]*HostConfig, error)

List ssh alias, filter by optional keyword

func UpdateHostCfg

func UpdateHostCfg(hostCfgPath string, aliasName string) ([]*HostConfig, error)

func (*HostConfig) ConnectionStr

func (hc *HostConfig) ConnectionStr() string

ConnectionStr return the connection string

func (*HostConfig) Display

func (hc *HostConfig) Display() bool

Display Whether to display connection string

type KeyType

type KeyType struct {
	Name                    string
	KeyBaseName             string
	SupportsVariableBitsize bool
}

KeyType abstracts configurations for various SSH key types like RSA and ED25519

func (KeyType) PrivateKey

func (kt KeyType) PrivateKey() string

PrivateKey returns the filename used by a keytype for the private component.

func (KeyType) PublicKey

func (kt KeyType) PublicKey() string

PublicKey returns the filename used by a keyType for the public component.

type KeyTypeRegistry

type KeyTypeRegistry map[string]KeyType

KeyTypeRegistry is used to store all the supported key types.

var SupportedKeyTypes KeyTypeRegistry

SupportedKeyTypes contains all key types supported by skm.

func (KeyTypeRegistry) GetByFilename

func (r KeyTypeRegistry) GetByFilename(name string) (KeyType, bool)

GetByFilename returns a key type object given the name of the private key's file. If no matching key type could be found, then the second return value is false.

type ListOption

type ListOption struct {
	// Keywords set Keyword filter records
	Keywords []string
	// IgnoreCase ignore case
	IgnoreCase bool
}

ListOption options for List

type MainConfig

type MainConfig struct {
	Basic    string   `yaml:"basic"`
	Contexts Contexts `yaml:"contexts"`
	Current  string   `yaml:"current"`
	// contains filtered or unexported fields
}

MainConfig main config struct

var (
	Main MainConfig
)

func MainConfigExample

func MainConfigExample(env *Environment) *MainConfig

main config example

func (*MainConfig) GetConfigPath

func (cfg *MainConfig) GetConfigPath() string

func (*MainConfig) LoadFrom

func (cfg *MainConfig) LoadFrom(filePath string) error

load config from yaml file

func (*MainConfig) SetConfigPath

func (cfg *MainConfig) SetConfigPath(configPath string)

func (*MainConfig) WriteTo

func (cfg *MainConfig) WriteTo(filePath string) error

write main config to yaml file

type SSHKey

type SSHKey struct {
	PublicKey  string
	PrivateKey string
	IsDefault  bool
	Type       *KeyType
	KeyDesc    string
	Alias      string
}

SSHKey struct includes both private/public keys & isDefault flag

type ServerConfig

type ServerConfig struct {
	Name                string        `yaml:"name"`
	Address             string        `yaml:"address"`
	Port                int           `yaml:"port,omitempty"`
	User                string        `yaml:"user,omitempty"`
	Password            string        `yaml:"password,omitempty"`
	PrivateKey          string        `yaml:"privateKey,omitempty"`
	PrivateKeyPassword  string        `yaml:"privateKey_password,omitempty"`
	Method              string        `yaml:"method"` // auth method default:key,options:password、key
	SuRoot              bool          `yaml:"su_root"`
	UseSudo             bool          `yaml:"use_sudo"`
	NoPasswordSudo      bool          `yaml:"no_password_sudo"`
	RootPassword        string        `yaml:"root_password"`
	ServerAliveInterval time.Duration `yaml:"server_alive_interval"`
}

ServerConfig server config

func (*ServerConfig) Terminal

func (s *ServerConfig) Terminal() error

start a ssh terminal

type Servers

type Servers []*ServerConfig

Servers myssh servers

func (Servers) Len

func (servers Servers) Len() int

func (Servers) Less

func (servers Servers) Less(i, j int) bool

func (Servers) Swap

func (servers Servers) Swap(i, j int)

Jump to

Keyboard shortcuts

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