https://github.com/petems/go-sshconfig
A golang library for parsing and writing SSH config files
https://github.com/petems/go-sshconfig
Last synced: 4 months ago
JSON representation
A golang library for parsing and writing SSH config files
- Host: GitHub
- URL: https://github.com/petems/go-sshconfig
- Owner: petems
- License: mit
- Created: 2020-03-08T17:28:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-01T07:43:30.000Z (7 months ago)
- Last Synced: 2025-01-12T16:37:59.731Z (6 months ago)
- Language: Go
- Homepage: https://godoc.org/github.com/petems/go-sshconfig
- Size: 340 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# go-sshconfig
[](https://travis-ci.com/petems/go-sshconfig)[](http://godoc.org/github.com/petems/go-sshconfig)[](https://goreportcard.com/report/github.com/petems/go-sshconfig)A simple [ssh_config](https://man.openbsd.org/ssh_config) parser/writer library
## Example
An app to add a global config entry to a config file:
```
sshConfigFile := os.ExpandEnv("$HOME/.ssh/config")file, err := os.Open(sshConfigFile)
if err != nil {
log.Fatal(err)
}config, err := sshconfig.Parse(file)
if err != nil {
log.Fatal(err)
}file.Close()
// modify by reference for existing params
// or create a new param and append it to global
if param := config.GetParam(sshconfig.VisualHostKeyKeyword); param != nil {
fmt.Println("VisualHostKey found! Switching to value: yes")
param.Args = []string{"yes"}
param.Comments = []string{"Added by the petems/go-sshconfig example app"}
} else {
fmt.Println("VisualHostKey not found! Adding with value: yes")
param = sshconfig.NewParam(sshconfig.VisualHostKeyKeyword, []string{"yes"}, []string{"Added by the petems/go-sshconfig example app"})
config.Globals = append(config.Globals, param)
}fmt.Println(config)
````$HOME/.ssh/config` contents:
```
Host github.com
ControlMaster auto
ControlPath ~/.ssh/ssh-%r@%h:%p
ControlPersist yes
User git
```Output:
```
VisualHostKey not found! Adding with value: yes
# global configuration# Added by the petems/go-sshconfig example app
VisualHostKey yes# host-based configuration
Host github.com
ControlMaster auto
ControlPath ~/.ssh/ssh-%r@%h:%p
ControlPersist yes
User git
```The best way to go deeper is to read the [docs](https://godoc.org/github.com/petems/go-sshconfig).
## Attribution
Forked and refactored from [emptyinterface/sshconfig/](https://github.com/emptyinterface/sshconfig/)
## Development
If you'd like to other features or anything else, check out the contributing guidelines in [CONTRIBUTING.md](CONTRIBUTING.md).