Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add storm-like helpers #151

Merged
merged 17 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ all: build
build: $(BINARIES)


.PHONY: docker
docker:
docker build -t moul/assh .


$(BINARIES): $(SOURCES)
$(GO) build -o $@ ./cmd/$@

Expand Down
71 changes: 65 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [Under the hood features](#under-the-hood-features)
3. [Configuration](#configuration)
4. [Usage](#usage)
* [Usage Examples](#usage-examples)
5. [Install](#install)
* [Register the wrapper (optional)](#register-the-wrapper-optional)
6. [Getting started](#getting-started)
Expand Down Expand Up @@ -300,7 +301,7 @@ USAGE:
assh [global options] command [command options] [arguments...]

VERSION:
2.3.0 (HEAD)
2.3.0+dev (HEAD)

AUTHOR(S):
Manfred Touron <https://github.com/moul/advanced-ssh-config>
Expand All @@ -309,15 +310,71 @@ COMMANDS:
proxy Connect to host SSH socket, used by ProxyCommand
build Build .ssh/config
info Display system-wide information
list List all hosts from assh config
search Search entries by given search text
wrapper Initialize assh, then run ssh/scp/rsync...
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--debug, -D Enable debug mode [$ASSH_DEBUG]
--verbose, -V Enable verbose mode
--help, -h show help
--config, -c "~/.ssh/assh.yml" Location of config file [$ASSH_CONFIG]
--debug, -D Enable debug mode [$ASSH_DEBUG]
--verbose, -V Enable verbose mode
--help, -h show help
--generate-bash-completion
--version, -v print the version
--version, -v print the version
```

### Usage examples

```console
$ assh list
Listing entries

*.scw -> root@[hostname_not_specified]:22
[custom options] StrictHostKeyChecking=no UserKnownHostsFile=/dev/null

*.shortcut1 -> bob@[hostname_not_specified]:22

*.shortcut2 -> bob@[hostname_not_specified]:22

bart -> [email protected]:22

bart-access -> bob@[hostname_not_specified]:22

dolphin -> bob@dolphin:24

expanded-host[0-7]* -> bob@%h.some.zone:22

homer -> [email protected]:2222

lisa-access -> bob@[hostname_not_specified]:22

maggie -> maggie@[hostname_not_specified]:22

marvin -> bob@[hostname_not_specified]:23

my-env-host -> user-moul@[hostname_not_specified]:22

schoolgw -> [email protected]:22
[custom options] ForwardX11=no

schooltemplate -> student@[hostname_not_specified]:22
[custom options] ForwardX11=yes IdentityFile=~/.ssh/school-rsa

vm-*.school.com -> bob@[hostname_not_specified]:22

(*) General options:
ControlMaster: auto
ControlPath: ~/tmp/.ssh/cm/%h-%p-%r.sock
ControlPersist: yes
Port: 22
User: bob
```

```console
$ assh search bart
Listing results for bart:
bart -> [email protected]:22
bart-access -> moul@[hostname_not_specified]:22
```

## Install
Expand Down Expand Up @@ -378,6 +435,8 @@ With the wrapper, `ssh` will *always* be called with an updated `~/.ssh/config`

### master (unreleased)

* Add a `assh --config=/path/to/assh.yml` option
* Add storm-like `assh list` and `assh search {keyword}` commands ([#151](https://github.com/moul/advanced-ssh-config/pull/151))
* Add an optional `ASSHBinaryPath` variable in the `assh.yml` file ([#148](https://github.com/moul/advanced-ssh-config/issues/148))

[Full commits list](https://github.com/moul/advanced-ssh-config/compare/v2.3.0...master)
Expand Down
6 changes: 6 additions & 0 deletions cmd/assh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func main() {
app.BashComplete = BashComplete

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
EnvVar: "ASSH_CONFIG",
Value: "~/.ssh/assh.yml",
Usage: "Location of config file",
},
cli.BoolFlag{
Name: "debug, D",
EnvVar: "ASSH_DEBUG",
Expand Down
125 changes: 125 additions & 0 deletions contrib/dummy-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
hosts:

homer:
# ssh homer -> ssh 1.2.3.4 -p 2222 -u robert
Hostname: 1.2.3.4
User: robert
Port: 2222

bart:
# ssh bart -> ssh 5.6.7.8 -u bart <- direct access
# or ssh 5.6.7.8/homer -u bart <- using homer as a gateway
Hostname: 5.6.7.8
User: bart
Gateways:
- direct # tries a direct access first
- homer # fallback on homer gateway

maggie:
# ssh maggie -> ssh 5.6.7.8 -u maggie <- direct access
# or ssh 5.6.7.8/homer -u maggie <- using homer as a gateway
User: maggie
Inherits:
- bart # inherits rules from "bart"

bart-access:
# ssh bart-access -> ssh home.simpson.springfield.us -u bart
Inherits:
- bart-template
- simpson-template

lisa-access:
# ssh lisa-access -> ssh home.simpson.springfield.us -u lisa
Inherits:
- lisa-template
- simpson-template

marvin:
# ssh marvin -> ssh marvin -p 23
# ssh sad-robot -> ssh sad-robot -p 23
# ssh bighead -> ssh bighead -p 23
# aliases inherit everything from marvin, except hostname
Port: 23
Aliases:
- sad-robot
- bighead

dolphin:
# ssh dolphin -> ssh dolphin -p 24
# ssh ecco -> ssh dolphin -p 24
# same as above, but with fixed hostname
Port: 24
Hostname: dolphin
Aliases:
- sad-robot
- bighead

schooltemplate:
User: student
IdentityFile: ~/.ssh/school-rsa
ForwardX11: yes

schoolgw:
# ssh school -> ssh gw.school.com -l student -o ForwardX11=no -i ~/.ssh/school-rsa
Hostname: gw.school.com
ForwardX11: no
Inherits:
- schooltemplate

"expanded-host[0-7]*":
# ssh somehost2042 -> ssh somehost2042.some.zone
Hostname: "%h.some.zone"

vm-*.school.com:
# ssh vm-42.school.com -> ssh vm-42.school.com/gw.school.com -l student -o ForwardX11=yes -i ~/.ssh/school-rsa
Gateways:
- schoolgw
Inherits:
- schooltemplate
# do not automatically create `ControlPath` -> may result in error
NoControlMasterMkdir: true

"*.shortcut1":
ResolveCommand: /bin/sh -c "echo %h | sed s/.shortcut1/.my-long-domain-name.com/"

"*.shortcut2":
ResolveCommand: /bin/sh -c "echo $(echo %h | sed s/.shortcut2//).my-other-long-domain-name.com"

"*.scw":
# ssh toto.scw -> 1. dynamically resolves the IP address
# 2. ssh {resolved ip address} -u root -p 22 -o UserKnownHostsFile=null -o StrictHostKeyChecking=no
# requires github.com/scaleway/scaleway-cli
ResolveCommand: /bin/sh -c "scw inspect -f {{.PublicAddress.IP}} server:$(echo %h | sed s/.scw//)"
User: root
Port: 22
UserKnownHostsFile: /dev/null
StrictHostKeyChecking: no

my-env-host:
User: user-$USER
Hostname: ${HOSTNAME}${HOSTNAME_SUFFIX}

templates:
# Templates are similar to Hosts, you can inherits from them
# but you cannot ssh to a template
bart-template:
User: bart
lisa-template:
User: lisa
simpson-template:
Host: home.simpson.springfield.us

defaults:
# Defaults are applied to each hosts
ControlMaster: auto
ControlPath: ~/tmp/.ssh/cm/%h-%p-%r.sock
ControlPersist: yes
Port: 22
User: bob

includes:
#- ~/.ssh/assh.d/*.yml
- /etc/assh.yml
- $ENV_VAR/blah-blah-*/*.yml

ASSHBinaryPath: ~/bin/assh # optionally set the path of assh
40 changes: 23 additions & 17 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ import:
- unix
- package: gopkg.in/yaml.v2
version: 7ad95dd0798a40da1ccdff6dff35fd177b5edf40
- package: github.com/mgutz/ansi
- package: golang.org/x/crypto
subpackages:
- ssh/terminal
2 changes: 1 addition & 1 deletion pkg/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func cmdBuild(c *cli.Context) {
conf, err := config.Open()
conf, err := config.Open(c.GlobalString("config"))
if err != nil {
Logger.Fatalf("Cannot open configuration file: %v", err)
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ var Commands = []cli.Command{
Usage: "Display system-wide information",
Action: cmdInfo,
},
{
Name: "list",
Usage: "List all hosts from assh config",
Action: cmdList,
},
{
Name: "search",
Usage: "Search entries by given search text",
Action: cmdSearch,
},
// FIXME: tree
{
Name: "wrapper",
Usage: "Initialize assh, then run ssh/scp/rsync...",
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func cmdInfo(c *cli.Context) {
conf, err := config.Open()
conf, err := config.Open(c.GlobalString("config"))
if err != nil {
panic(err)
}
Expand Down
Loading