https://github.com/piger/sshconfig
This package implements a simple parser for the ssh_config(5) configuration file used by OpenSSH.
https://github.com/piger/sshconfig
go golang parser ssh ssh-config
Last synced: 4 months ago
JSON representation
This package implements a simple parser for the ssh_config(5) configuration file used by OpenSSH.
- Host: GitHub
- URL: https://github.com/piger/sshconfig
- Owner: piger
- License: bsd-2-clause
- Created: 2018-02-23T20:45:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T14:49:59.000Z (about 2 years ago)
- Last Synced: 2025-02-28T17:09:12.093Z (4 months ago)
- Topics: go, golang, parser, ssh, ssh-config
- Language: Go
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenSSH ssh_config(5) parser
This package implements a simple parser for the `ssh_config(5)` configuration file used by
OpenSSH.This package at the moment only supports a subset of the syntax used by `ssh_config(5)`; the current
implemented features are:- consider only the first value found for each option
- expand some tokens (like `%h` and `%p`) for specific options (e.g. `ProxyCommand`)
- `Host` pattern matching and patterns negation are supportedSee the documentation at [godoc.org](https://godoc.org/github.com/piger/sshconfig).
## Example usage
You create `SSHConfig` objects by calling `ReadSSHConfig(filename string)` which can be used to
lookup SSH options for a specific name (which can be either a hostname or a *alias*).import (
"github.com/piger/sshconfig"
)sshConfig, err := ReadSSHConfig("/home/myuser/.ssh/config)
if err != nil {
log.Fatal(err)
}hostConfig, err := sshConfig.Lookup("db1.example.com")
if err != nil {
log.Fatal(err)
}if opt, ok := hostConfig["hostname"]; ok {
fmt.Printf("ProxyCommand for db1: %s", opt)
}## Notes
- Option names are converted to lowercase during parsing of the configuration file