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: 7 days 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 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T14:49:59.000Z (about 3 years ago)
- Last Synced: 2025-10-12T07:29:08.293Z (8 months ago)
- Topics: go, golang, parser, ssh, ssh-config
- Language: Go
- Size: 13.7 KB
- Stars: 0
- Watchers: 0
- 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 supported
See 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