sshman

package module
v0.0.0-...-8729f90 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 13 Imported by: 0

README

sshman

sshman is a command line tool for managing your ssh alias config easily, inspired by storm project, powered by Go.

Feature

Install

Gopher
go get -u github.com/sonnt85/sshman/cmd
Homebrew
brew tap sonnt85/tap
brew install sonnt85/tap/sshman
Manual

Download it from releases, and extract it to your PATH directory.

Usage

% sshman
NAME:
   sshman - Manage your ssh alias configs easily

USAGE:
   sshman [global options] command [command options] [arguments...]

VERSION:
   master

COMMANDS:
     add, a     Add a new SSH alias record
     list, l    List or query SSH alias records
     update, u  Update SSH record by specifying alias name
     delete, d  Delete SSH records by specifying alias names
     backup, b  Backup SSH config files
     get, g     Get opt of first alias  match
     completion generate the autocompletion script for the specified shell
     help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --file value, -f value  (default: "/Users/wendell/.ssh/config")
   --help, -h              show help
   --version, -v           print the version
Add a new alias
# sshman add test2 2.2.2.2
# sshman add test1 root@1.1.1.1:77 -c IdentityFile=~/.ssh/wendell
% sshman add test1 root@1.1.1.1:77 -i ~/.ssh/wendell
✔ alias[test1] added successfully.

        test1 -> root@1.1.1.1:77
                identityfile = /Users/wendell/.ssh/wendell

Username and port config is optional, the username is current login username and port is 22 by default.
Using -c to set more config options. For convenience, -i xxx can instead of -c identityfile=xxx.

List or query alias
# sshman list
# sshman list "*"
# sshman list Test -ic
% sshman list test1 77
✔ Listing 1 records.

        test1 -> root@1.1.1.1:77
                identityfile = /Users/wendell/.ssh/wendell

It will display all alias records If no params offered, or it will using params as keywords query alias records.
If there is a -it option, it will ignore case when searching.

Update an alias
# sshman update test1 -r test2
# sshman update test1 root@1.1.1.1:22022
% sshman update test1 -i "" -r test3 -c hostname=3.3.3.3 -c port=22022
✔ alias[test3] updated successfully.

        test3 -> root@3.3.3.3:22022

Update an existing alias record, it will replace origin user, hostname, port config's if connected string param offered.
You can use -c to update single and extra config option, -c identityfile= -c proxycommand= will remove identityfile and proxycommand options.
For convenience, -i xxx can instead of -c identityfile=xxx
Rename the alias specified by -r flag.

Delete one or more alias
# sshman delete test1
% sshman delete test1 test2
✔ alias[test1,test2] deleted successfully.
Backup ssh config
% sshman backup ./config_backup
✔ backup ssh config to [./config_backup] successfully.

For Include directive

If you use the Include directive, there are some extra notes.

Add -p(--path) flag for list,add,update,delete command to show the file path where the alias is located, it can also be set by the SSHMAN_SHOW_PATH environment variable.

SSHMAN_SHOW_PATH

Set to true to show the file path where the alias is located. Default is false.


Add -ap(--addpath) flag for add command to specify the file path to which the alias is added, it can also be set by the SSHMAN_ADD_PATH environment variable.

SSHMAN_ADD_PATH

This file path indicates to which file to add the alias. Default is the entry config file.


For convenience, you can export these environments in your .zshrc or .bashrc, example:

export SSHMAN_SHOW_PATH=true
export SSHMAN_ADD_PATH=~/.ssh/config.d/temp

Licence

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SuccessFlag success flag
	SuccessFlag = color.GreenString("✔ ")
	// ErrorFlag error flag
	ErrorFlag = color.RedString("✗ ")
)

Functions

func ArgumentsCheck

func ArgumentsCheck(argCount, min, max int) error

ArgumentsCheck check arguments count correctness

func GetFilePaths

func GetFilePaths(p string) ([]string, error)

GetFilePaths get file paths

func GetHomeDir

func GetHomeDir() string

GetHomeDir return user's home directory

func GetUsername

func GetUsername() string

GetUsername return current username

func ParseConnect

func ParseConnect(connect string) (string, string, string)

ParseConnect parse connect string, format is [user@]host[:port]

func Query

func Query(values, keys []string, ignoreCase bool) bool

Query values contains keys, key is parterm

func SortKeys

func SortKeys(m map[string]string) []string

SortKeys sort map keys

Types

type AddOption

type AddOption struct {
	// Path add path
	Path string
	// Alias alias
	Alias string
	// Connect connection string
	Connect string
	// Config other config
	Config map[string]string
}

AddOption options for Add

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][]*sshconfig.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 Add

func Add(p string, ao *AddOption) (*HostConfig, error)

Add ssh host config to ssh config file

func Delete

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

Delete existing alias record

func List

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

List ssh alias, filter by optional keyword

func NewHostConfig

func NewHostConfig(alias, path string, host *sshconfig.Host) *HostConfig

NewHostConfig new HostConfig

func Update

func Update(p string, uo *UpdateOption) (*HostConfig, error)

Update existing record

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 ListOption

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

ListOption options for List

type UpdateOption

type UpdateOption struct {
	// Alias alias
	Alias string
	// NewAlias new alias
	NewAlias string
	// Connect connection string
	Connect string
	// Config other config
	Config map[string]string
}

UpdateOption options for Update

func (*UpdateOption) Valid

func (uo *UpdateOption) Valid() bool

Valid whether the option is valid

Directories

Path Synopsis
cmd
Package sshconfig provides tools for manipulating SSH config files.
Package sshconfig provides tools for manipulating SSH config files.

Jump to

Keyboard shortcuts

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