skm

package module
v0.0.0-...-7560066 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2018 License: MIT Imports: 8 Imported by: 0

README

Release MIT licensed Build Status Go Report Card GoCover.io GoDoc

SKM is a simple and powerful SSH Keys Manager. It helps you to manage your multiple SSH keys easily!

Features

  • Create, List, Delete your SSH key(s)
  • Manage all your SSH keys by alias names
  • Choose and set a default SSH key
  • Copy default SSH key to a remote host
  • Rename SSH key alias name
  • Backup and restore all your SSH keys
  • Prompt UI for SSH key selection

Installation

Homebrew
brew tap timothyye/tap
brew install timothyye/tap/skm
Using Go
go get github.com/TimothyYe/skm/cmd/skm
Manual Installation

Download it from releases and extact it to /usr/bin or your PATH directory.

Usage

% skm

SKM V0.5
https://github.com/TimothyYe/skm

NAME:
   SKM - Manage your multiple SSH keys easily

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

VERSION:
   0.5

COMMANDS:
     init, i      Initialize SSH keys store for the first time usage.
     create, c    Create a new SSH key.
     ls, l        List all the available SSH keys
     use, u       Set specific SSH key as default by its alias name
     delete, d    Delete specific SSH key by alias name
     rename, rn   Rename SSH key alias name to a new one
     copy, cp     Copy current SSH public key to a remote host
		 display, dp  Display the current SSH public key
     backup, b    Backup all SSH keys to an archive file
     restore, r   Restore SSH keys from an existing archive file
     help, h      Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version

For the first time use

You should initialize the SSH key store for the first time use:

% skm init

✔ SSH key store initialized!

So, where are my SSH keys? SKM will create SSH key store at $HOME/.skm and put all the SSH keys in it.

NOTE: If you already have id_rsa & id_rsa.pub key pairs in $HOME/.ssh, SKM will move them to $HOME/.skm/default

Create a new SSH key

NOTE: Currently ONLY RSA key type is supported!

skm create prod -C "abc@abc.com"

Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/timothy/.skm/prod/id_rsa.
Your public key has been saved in /Users/timothy/.skm/prod/id_rsa.pub.
...
✔ SSH key [prod] created!

List SSH keys

% skm ls

✔ Found 3 SSH key(s)!

->      default
        dev
        prod

Set default SSH key

% skm use dev
Now using SSH key: dev

Prompt UI for key selection

You can just type skm use, then a prompt UI will help you to choose the right SSH key:

Delete a SSH key

% skm delete prod

Please confirm to delete SSH key [prod] [y/n]: y
✔ SSH key [prod] deleted!

Copy SSH public key to a remote host

% skm cp timothy@example.com

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/timothy/.skm/default/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
timothy@example.com's password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'timothy@example.com'"
and check to make sure that only the key(s) you wanted were added.

✔  Current SSH key already copied to remote host

Rename a SSH key with a new alias name

% skm rn test tmp
✔  SSH key [test] renamed to [tmp]

Backup SSH keys

Backup all your SSH keys to $HOME directory by default.

% skm backup

a .
a ./test
a ./default
a ./dev
a ./dev/id_rsa
a ./dev/id_rsa.pub
a ./default/id_rsa
a ./default/id_rsa.pub
a ./test/id_rsa
a ./test/id_rsa.pub

✔  All SSH keys backup to: /Users/timothy/skm-20171016170707.tar

Restore SSH keys

% skm restore ~/skm-20171016172828.tar.gz                                                                                           
x ./
x ./test/
x ./default/
x ./dev/
x ./dev/id_rsa
x ./dev/id_rsa.pub
x ./default/._id_rsa
x ./default/id_rsa
x ./default/._id_rsa.pub
x ./default/id_rsa.pub
x ./test/id_rsa
x ./test/id_rsa.pub

✔  All SSH keys restored to /Users/timothy/.skm

Hook mechanism

Edit and place a executable file named hook at the specified key directory, for example:

~/.skm/prod/hook

This hook file can be both an executable binary file or an executable script file.

SKM will call this hook file after switching default SSH key to it, you can do some stuff in this hook file.

Licence

MIT License

Documentation

Index

Constants

View Source
const (
	// Name is the program name
	Name = "SKM"
	// Usage is for simple description
	Usage = "Manage your multiple SSH keys easily"

	// CheckSymbol is the code for check symbol
	CheckSymbol = "\u2714 "
	// CrossSymbol is the code for check symbol
	CrossSymbol = "\u2716 "

	// PublicKey is the default name of SSH public key
	PublicKey = "id_rsa.pub"
	// PrivateKey is the default name of SSH private key
	PrivateKey = "id_rsa"
	// 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"
)

Variables

View Source
var (
	// StorePath is the default SKM key path to store all the SSH keys
	StorePath = filepath.Join(os.Getenv("HOME"), ".skm")
	// SSHPath is the default SSH key path
	SSHPath = filepath.Join(os.Getenv("HOME"), ".ssh")
)

Functions

func ClearKey

func ClearKey()

ClearKey clears both private & public keys from SSH key path

func CreateLink(alias string)

CreateLink creates symbol link for specified SSH key

func DeleteKey

func DeleteKey(alias string, key *SSHKey, forTest ...bool)

DeleteKey delete key by its alias name

func Execute

func Execute(workDir, script string, args ...string) bool

Execute executes shell commands with arguments

func GetBakFileName

func GetBakFileName() string

GetBakFileName generates a backup file name by current date and time

func IsEmpty

func IsEmpty(path string) (bool, error)

IsEmpty checks if directory in path is empty

func LoadSSHKeys

func LoadSSHKeys() map[string]*SSHKey

LoadSSHKeys loads all the SSH keys from key store

func ParsePath

func ParsePath(path string) string

ParsePath return the original SSH key path if it is a symbol link

func RunHook

func RunHook(alias string)

RunHook runs hook file after switching SSH key

Types

type SSHKey

type SSHKey struct {
	PublicKey  string
	PrivateKey string
	IsDefault  bool
}

SSHKey struct includes both private/public keys & isDefault flag

Directories

Path Synopsis
cmd
skm

Jump to

Keyboard shortcuts

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