Giter Club home page Giter Club logo

manssh's Introduction

manssh

Release Build Status Go Report Card GoCover.io GoDoc DUB

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

Note:
This project is actually a simple glue project, the most complex and core parsing ssh config file logic implements by ssh_config, I didn't do much.
At first it was just a imitation of storm, now it has become a little different.

Feature

Install

Go

Before 1.17

go get -u github.com/xwjdsh/manssh/cmd/manssh

1.17 or higher

go install github.com/xwjdsh/manssh/cmd/manssh

Homebrew

brew tap xwjdsh/tap
brew install xwjdsh/tap/manssh

Docker

alias manssh='docker run -t --rm -v ~/.ssh/config:/root/.ssh/config wendellsun/manssh'

Manual

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

Usage

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

USAGE:
   manssh [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
     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

# manssh add test2 2.2.2.2
# manssh add test1 [email protected]:77 -c IdentityFile=~/.ssh/wendell
% manssh add test1 [email protected]:77 -i ~/.ssh/wendell
✔ alias[test1] added successfully.

        test1 -> [email protected]: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

# manssh list
# manssh list "*"
# manssh list Test -ic
% manssh list test1 77
✔ Listing 1 records.

        test1 -> [email protected]: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

# manssh update test1 -r test2
# manssh update test1 [email protected]:22022
% manssh update test1 -i "" -r test3 -c hostname=3.3.3.3 -c port=22022
✔ alias[test3] updated successfully.

        test3 -> [email protected]: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

# manssh delete test1
% manssh delete test1 test2
✔ alias[test1,test2] deleted successfully.

Backup ssh config

% manssh 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 MANSSH_SHOW_PATH environment variable.

MANSSH_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 MANSSH_ADD_PATH environment variable.

MANSSH_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 MANSSH_SHOW_PATH=true
export MANSSH_ADD_PATH=~/.ssh/config.d/temp

Thanks

Licence

MIT License

manssh's People

Contributors

sbrownjc avatar timothyye avatar trigged avatar xwjdsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

manssh's Issues

Match directive parsing is unsupported

SSH config file contains

Match all
  Include ~/.fig/ssh

When I try to execute manssh l I receive an exception ✗ (205, 7): ssh_config: Match directive parsing is unsupported

Environment:
MacOS 13.3.1
zsh 5.9 (x86_64-apple-darwin22.0)
OpenSSH_9.0p1, LibreSSL 3.3.6

Panic when trying to update existing config

Adding works fine:

$ cat ~/.ssh/config
$ manssh add github.com -c ControlMaster=auto -c ControlPath=~/.ssh/ssh-%r@%h:%p -c ControlPersist=yes -c User=git -c IdentityFile=~/.ssh/github_ssh_key_10_Mar_2020
✔  added successfully

	github.com
	    controlmaster = auto
	    controlpath = /Users/petersouter/.ssh/ssh-%r@%h:%p
	    controlpersist = yes
	    identityfile = /Users/petersouter/.ssh/github_ssh_key_10_Mar_2020
	    user = git
	    port = 22

But updating crashes and removes the entry:

$ manssh update github.com -c ControlMaster=auto -c ControlPath=~/.ssh/ssh-%r@%h:%p -c ControlPersist=yes -c User=git -c IdentityFile=~/.ssh/github_ssh_key_10_Mar_2020
✔  updated successfully

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1159eaa]

goroutine 1 [running]:
main.printHost(0xc4200cc400, 0x0)
	/Users/wendell/Working/GOPATH/src/github.com/xwjdsh/manssh/cmd/manssh/print.go:47 +0x3a
main.updateCmd(0xc4200cc420, 0x0, 0xc4200cc420)
	/Users/wendell/Working/GOPATH/src/github.com/xwjdsh/manssh/cmd/manssh/actions.go:110 +0x450
github.com/xwjdsh/manssh/vendor/github.com/urfave/cli.HandleAction(0x1181000, 0x11c5958, 0xc4200cc420, 0xc420084100, 0x0)
	/Users/wendell/Working/GOPATH/src/github.com/xwjdsh/manssh/vendor/github.com/urfave/cli/app.go:490 +0xc8
github.com/xwjdsh/manssh/vendor/github.com/urfave/cli.Command.Run(0x11bac27, 0x6, 0x0, 0x0, 0xc420066560, 0x1, 0x1, 0x11c03e4, 0x1e, 0x0, ...)
	/Users/wendell/Working/GOPATH/src/github.com/xwjdsh/manssh/vendor/github.com/urfave/cli/command.go:210 +0xa36
github.com/xwjdsh/manssh/vendor/github.com/urfave/cli.(*App).Run(0xc4200a84e0, 0xc420010750, 0xd, 0xd, 0x0, 0x0)
	/Users/wendell/Working/GOPATH/src/github.com/xwjdsh/manssh/vendor/github.com/urfave/cli/app.go:255 +0x6a0
main.main()
	/Users/wendell/Working/GOPATH/src/github.com/xwjdsh/manssh/cmd/manssh/main.go:21 +0x11c

panic: runtime error: invalid memory address or nil pointer dereference & SIGSEGV

Configuration

OS: Ubuntu 16.04
go version: go1.10.2 linux/amd64

Process I've done

Then I do an install with

go get -u github.com/xwjdsh/manssh/cmd/manssh

and run the following

manssh list

It returns this error trace

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x52c814]

goroutine 1 [running]:
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.decode.func1(0xc4200616e8)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/config.go:216 +0x1f2
panic(0x579640, 0x68f8d0)
	/usr/local/go/src/runtime/panic.go:502 +0x229
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.(*sshParser).parseKV(0xc4200be1e0, 0xc42009ff20)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/parser.go:99 +0x264
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.(*sshParser).(github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.parseKV)-fm(0xc42009ff20)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/parser.go:80 +0x2a
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.(*sshParser).run(0xc4200be1e0)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/parser.go:38 +0x42
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.parseSSH(0xc420094180, 0xc4200b0000, 0xc420094180)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/parser.go:180 +0x307
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.decode(0x5c7680, 0xc4200b8048, 0x0, 0x0, 0x0, 0x0)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/config.go:226 +0x90
github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config.Decode(0x5c7680, 0xc4200b8048, 0x440, 0x180, 0xc4200b8048)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/xwjdsh/ssh_config/config.go:209 +0x3c
github.com/xwjdsh/manssh.ParseConfig(0xc4200b6e20, 0x19, 0x0, 0x0)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/sshconfig.go:26 +0x78
github.com/xwjdsh/manssh.List(0xc4200b6e20, 0x19, 0x6b3800, 0x0, 0x0, 0xc420061a77, 0x1, 0x1, 0x5, 0x4, ...)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/sshconfig.go:38 +0x6e
main.list(0xc4200c42c0, 0x0, 0xc4200c42c0)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/cmd/manssh/actions.go:17 +0xe1
github.com/xwjdsh/manssh/vendor/github.com/urfave/cli.HandleAction(0x570100, 0x5b1a18, 0xc4200c42c0, 0xc4200be100, 0x0)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/urfave/cli/app.go:490 +0xc8
github.com/xwjdsh/manssh/vendor/github.com/urfave/cli.Command.Run(0x5a69d0, 0x4, 0x0, 0x0, 0xc42009e470, 0x1, 0x1, 0x5ac7f3, 0x1f, 0x0, ...)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/urfave/cli/command.go:210 +0xa36
github.com/xwjdsh/manssh/vendor/github.com/urfave/cli.(*App).Run(0xc4200c04e0, 0xc4200aa020, 0x2, 0x2, 0x0, 0x0)
	/home/thomasg/go/src/github.com/xwjdsh/manssh/vendor/github.com/urfave/cli/app.go:255 +0x6a0
main.main()
	/home/thomasg/go/src/github.com/xwjdsh/manssh/cmd/manssh/main.go:21 +0x11c

I also tried directly with the release file manssh_0.4.0_linux_amd64.tar.gz from https://github.com/xwjdsh/manssh/releases

take `Include` directive into consideration

All my aliases are defined in different config files, using ssh_config Include directive.

serge  minos  ~ 
➡  cat .ssh/config
Include config.d/*

serge  minos  ~ 
➡  manssh list
✔ Listing 0 records.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.