utils

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHostKeyToKnownHosts

func AddHostKeyToKnownHosts(host string, key ssh.PublicKey, knownHostsPath string) error

AddHostKeyToKnownHosts updates user known_hosts file adding the host key

func ByteCountSI added in v0.9.0

func ByteCountSI(b int64) string

func CurrentUser added in v0.12.1

func CurrentUser() *user.User

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey *ecdsa.PrivateKey) []byte

EncodePrivateKeyToPEM converts a private key object to PEM

func ExpandUserHome

func ExpandUserHome(path string) (string, error)

ExpandUserHome resolve paths like "~/.ssh/id_rsa"

func GeneratePrivateKey

func GeneratePrivateKey() (*ecdsa.PrivateKey, error)

GeneratePrivateKey generate an rsa key (actually used from the sshd server)

func GeneratePublicKey

func GeneratePublicKey(key *ecdsa.PublicKey) ([]byte, error)

GeneratePublicKey generates a public key from a private one

func GetUserDefaultShell

func GetUserDefaultShell(username string) string

GetUserDefaultShell try to get the best shell for the user

func LoadIdentityFile

func LoadIdentityFile(file string) (ssh.AuthMethod, error)

LoadIdentityFile reads a public key file and loads the keys to an ssh.PublicKeys object

func ParseSSHUrl

func ParseSSHUrl(url string) *sshUrl

ParseSSHUrl build an sshUrl object from an url string

func PrettyPrintStruct added in v0.15.0

func PrettyPrintStruct(v interface{})

PrettyPrintStruct prints a struct in a readable JSON format

func SerializePublicKey

func SerializePublicKey(k ssh.PublicKey) string

SerializePublicKey converts an ssh.PublicKey to printable bas64 string

func WriteKeyToFile

func WriteKeyToFile(keyBytes []byte, keyPath string) error

WriteKeyToFile stores a key to the specified path

Types

type Endpoint

type Endpoint struct {
	Host string
	Port int
}

Endpoint holds the tunnel endpoint details

func NewEndpoint

func NewEndpoint(s string) *Endpoint

NewEndpoint builds an Endpoint object

func (*Endpoint) String

func (endpoint *Endpoint) String() string

String returns the string representation of the endpoint

type NodeConfig added in v0.15.0

type NodeConfig struct {
	Host                  string
	Port                  int
	HostName              string
	User                  string
	IdentityFile          string
	StrictHostKeyChecking bool
	UserKnownHostsFile    string
	ProxyJump             string
}

type SSHConfigParser added in v0.15.0

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

func GetSSHConfigInstance added in v0.15.0

func GetSSHConfigInstance() *SSHConfigParser

GetSSHConfigInstance ensures the singleton is initialized only once

func (*SSHConfigParser) GetHostConf added in v0.15.0

func (s *SSHConfigParser) GetHostConf(host string) *NodeConfig

func (*SSHConfigParser) GetHostNames added in v0.15.0

func (s *SSHConfigParser) GetHostNames() []string

Jump to

Keyboard shortcuts

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