### Full assh Configuration Example (YAML) Source: https://github.com/moul/assh/blob/master/README.md This comprehensive YAML snippet illustrates the structure of a typical `~/.ssh/assh.yml` file. It includes sections for defining `hosts` with various options (Hostname, User, Port, Gateways, Inherits, Aliases, RateLimit, ResolveCommand), reusable `templates`, global `defaults` (ControlMaster, ControlPath, ControlPersist, Port, User, Hooks), and `includes` for modularity. It showcases inheritance, templating, gateway configurations, dynamic host resolution, and various hook examples within the defaults section. ```yaml 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: ecco RateLimit: 10M # 10Mbytes/second rate limiting 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" "*.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 inherit 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 Hooks: # Automatically backup ~/.ssh/config BeforeConfigWrite: - 'exec set -x; cp {{.SSHConfigPath}} {{.SSHConfigPath}}.bkp' AfterConfigWrite: # Concat another `ssh_config` file with the one just generated by `assh` - 'exec cat ~/.ssh/my-heroku-generated-config >> {{.SSHConfigPath}}' # Alert me with a Desktop notification - notify "{{.SSHConfigPath}} has been rewritten" OnConnect: # Log internal information to a file - exec printf '{{.}}' | jq . >> ~/.ssh/last_connected_host.txt # Alert me with a Desktop notification - notify New SSH connection to {{.Host.Prototype}} at {{.Stats.ConnectedAt}} # Write the host prototype to the terminal stderr - write New SSH connection to {{.Host.Prototype}} OnDisconnect: # write on terminal and in a Desktop notification some statistics about the finished connection - "write SSH connection to {{.Host.HostName}} closed, {{.Stats.WrittenBytes }} bytes written in {{.Stats.ConnectionDuration}} ({{.Stats.AverageSpeed}}bps)" - "notify SSH connection to {{.Host.HostName}} closed, {{.Stats.WrittenBytes }} bytes written in {{.Stats.ConnectionDuration}} ({{.Stats.AverageSpeed}}bps)" includes: - ~/.ssh/assh.d/*.yml - /etc/assh.yml - $ENV_VAR/blah-blah-*/*.yml ASSHBinaryPath: ~/bin/assh # optionally set the path of assh ``` -------------------------------- ### Building assh Config File (Console) Source: https://github.com/moul/assh/blob/master/README.md This console snippet provides an example of using the `assh config build` command. This command processes the `assh.yml` configuration and outputs the generated SSH configuration to standard output, which is then redirected to overwrite the user's `~/.ssh/config` file. ```console $ assh config build > ~/.ssh/config ``` -------------------------------- ### Defining SSH Hosts and Gateways in assh YAML Config Source: https://github.com/moul/assh/blob/master/README.md Provides an example assh.yml configuration file defining hosts, their hostnames, and gateway relationships. Demonstrates simple direct connections, single-gateway connections, and chained gateway connections, including a fallback mechanism using 'direct'. ```yaml hosts:\n hosta:\n Hostname: 1.2.3.4\n\n hostb:\n Hostname: 5.6.7.8\n Gateways: hosta\n\n hostc:\n Hostname: 9.10.11.12\n Gateways: hostb\n\n hostd:\n Hostname: 13.14.15.16\n GatewayConnectTimeout: 2\n Gateways:\n - direct\n - hosta ``` -------------------------------- ### Configuring OnConnect Exec Hook in assh YAML Source: https://github.com/moul/assh/blob/master/README.md Shows how to configure an assh hook using the 'exec' driver in the YAML configuration. This example uses the OnConnect event to execute a shell command (echoing host details and piping to jq) upon a successful connection, demonstrating the use of Golang template variables within the command. ```yaml defaults:\n Hooks:\n OnConnect: exec echo '{{.Host}}' | jq . ``` -------------------------------- ### Using assh for Simple SSH Gateway (Command Line) Source: https://github.com/moul/assh/blob/master/README.md Demonstrates connecting to a host via a single gateway using assh's simplified syntax. Includes the equivalent standard OpenSSH command for comparison. ```console $ ssh hosta/hostb\nuser@hosta $ ``` ```console $ ssh -o ProxyCommand="ssh hostb nc %h %p" hosta ``` -------------------------------- ### Using assh for Chained SSH Gateways (Command Line) Source: https://github.com/moul/assh/blob/master/README.md Illustrates connecting to a host through multiple chained gateways using assh's concise syntax. Shows the complex equivalent standard OpenSSH command required. ```console $ ssh hosta/hostb/hostc\nuser@hosta $ ``` ```console $ ssh -o ProxyCommand="ssh -o ProxyCommand='ssh hostc nc %h %p' hostb nc %h %p" hosta ``` -------------------------------- ### Displaying assh CLI Usage (Console) Source: https://github.com/moul/assh/blob/master/README.md This console snippet shows the basic command-line usage of the `assh` tool. It lists the available commands (`ping`, `info`, `config`, `sockets`, `help`) and global options for controlling behavior like configuration file location, debug mode, and verbosity. ```console NAME: assh - advanced ssh config USAGE: assh [global options] command [command options] [arguments...] VERSION: 2.8.0 (HEAD) AUTHOR(S): Manfred Touron COMMANDS: ping Send packets to the SSH server and display statistics info Display system-wide information config Manage ssh and assh configuration sockets Manage control sockets help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --config value, -c value Location of config file (default: "~/.ssh/assh.yml") [$ASSH_CONFIG] --debug, -D Enable debug mode [$ASSH_DEBUG] --verbose, -V Enable verbose mode --help, -h show help --version, -v print the version ``` -------------------------------- ### Configuring BeforeConfigWrite Hook (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet demonstrates a hook (`BeforeConfigWrite`) that runs just before assh rewrites the `~/.ssh/config` file. It uses the `exec` driver to execute a command that creates a backup copy of the existing config file. ```yaml defaults: Hooks: BeforeConfigWrite: exec cp {{.SSHConfigPath}} {{.SSHConfigPath}}.backup # make a copy of ~/.ssh/config before being rewritten ``` -------------------------------- ### Using Write Driver OnConnect (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet illustrates the use of the `write` driver within an `OnConnect` hook. The `write` driver sends the specified string, interpreted as a Golang template, to the standard output (terminal) when a connection is established. ```yaml defaults: Hooks: OnConnect: - write New SSH connection to {{.Host.Prototype}}. # writes: "New SSH connection to moul@127.0.0.1:22." on the terminal on connection ``` -------------------------------- ### Using Notify Driver OnConnect (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet shows the configuration for the `notify` driver in an `OnConnect` hook. This driver sends a desktop notification upon establishing an SSH connection, using the provided string as the notification message, which is parsed as a Golang template. ```yaml defaults: Hooks: OnConnect: notify New SSH connection to {{.Host.Prototype}}. ``` -------------------------------- ### Processing assh Output with jq (Shell) Source: https://github.com/moul/assh/blob/master/README.md Demonstrates how assh can output internal data (like a host's parsed configuration) as JSON, which can then be piped to tools like `jq` for pretty printing or further processing. This shows the structured nature of assh's internal data. ```shell # executes: `echo '{"HostName":"localhost","Port":"22","User":"moul","ControlPersist":"yes",...}' | jq . # which results in printing a pretty JSON of the host # { # "HostName": "localhost", # "Port": "22", # "User": "moul", # "ControlPersist": "yes", # ... # } ``` -------------------------------- ### Configuring OnConnect Hook with exec (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet shows how to configure a hook that executes a shell command when an SSH connection is established (`OnConnect`). It uses the `exec` driver to pipe a message about the connection prototype to the `mail` command, sending an email. ```yaml defaults: Hooks: OnConnect: exec echo 'New SSH connection to {{.Host.Prototype}}.' | mail -s "SSH connection journal" m+assh@42.am # send an email with the connection prototype ``` -------------------------------- ### Executing Background Hook (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet shows how to run a command in the background using the `exec` driver within an `OnConnect` hook. Appending `&` to the command makes it non-blocking, allowing the SSH connection to proceed while the hooked process runs independently. ```yaml defaults: Hooks: OnConnect: - exec sleep 60 & # execute the `sleep 60` command in background (non-blocking) # if you quit your ssh connection, the process will continue in background. ``` -------------------------------- ### Using Notify Driver OnDisconnect (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet demonstrates using the `notify` driver within an `OnDisconnect` hook. It triggers a desktop notification when an SSH connection closes, displaying statistics about the connection duration, written bytes, and average speed. ```yaml defaults: Hooks: OnDisconnect: - "notify SSH connection to {{.Host.Name}} closed, {{ .Stats.WrittenBytes }} bytes written in {{ .Stats.ConnectionDuration }} ({{ .Stats.AverageSpeed}})" ``` -------------------------------- ### Appending Date to Config After Write Hook (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet configures an `AfterConfigWrite` hook, executed after assh has written the new `~/.ssh/config` file. It uses the `exec` driver to append a comment containing the current date to the generated configuration file. ```yaml defaults: Hooks: AfterConfigWrite: 'exec echo "# date: `date`" >> {{.SSHConfigPath}}' # Append a comment with the compilation date to the generated ~/.ssh/config file ``` -------------------------------- ### Appending External Config After Write Hook (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet demonstrates another use of the `AfterConfigWrite` hook. It utilizes the `exec` driver to concatenate the content of another external SSH configuration file (`/path/to/my/provider/generated/.ssh/config`) onto the end of the `~/.ssh/config` file generated by assh. ```yaml defaults: Hooks: AfterConfigWrite: 'exec cat /path/to/my/provider/generated/.ssh/config >> {{.SSHConfigPath}}' # Append another .ssh/config file to the generated .ssh/config file ``` -------------------------------- ### Using Write Driver OnDisconnect (YAML) Source: https://github.com/moul/assh/blob/master/README.md This YAML snippet demonstrates using the `write` driver in an `OnDisconnect` hook. It writes a message containing connection statistics (written bytes, duration, average speed) to the terminal when the SSH connection is closed. ```yaml defaults: Hooks: OnDisconnect: - "write SSH connection to {{.Host.Name}} closed, {{ .Stats.WrittenBytes }} bytes written in {{ .Stats.ConnectionDuration }} ({{ .Stats.AverageSpeed}})" # writes: SSH connection to localhost closed, 40 bytes written. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.