{"id":13646820,"url":"https://github.com/kevinburke/ssh_config","last_synced_at":"2025-05-14T13:08:41.066Z","repository":{"id":41070776,"uuid":"88535718","full_name":"kevinburke/ssh_config","owner":"kevinburke","description":"Go parser for ssh_config files","archived":false,"fork":false,"pushed_at":"2025-02-20T08:21:10.000Z","size":86,"stargazers_count":447,"open_issues_count":28,"forks_count":69,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-14T02:11:13.965Z","etag":null,"topics":["golang","parser","ssh","ssh-config"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/kevinburke/ssh_config","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinburke.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-04-17T18:06:25.000Z","updated_at":"2025-05-03T19:22:54.000Z","dependencies_parsed_at":"2022-09-17T04:51:39.613Z","dependency_job_id":"9d668721-c5e5-4234-858d-ddb41148c6ad","html_url":"https://github.com/kevinburke/ssh_config","commit_stats":{"total_commits":66,"total_committers":9,"mean_commits":7.333333333333333,"dds":"0.13636363636363635","last_synced_commit":"1d09c0b50564c4a7f8c56c9d5d6d935e06ee94da"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fssh_config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fssh_config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fssh_config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fssh_config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinburke","download_url":"https://codeload.github.com/kevinburke/ssh_config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149975,"owners_count":22022852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","parser","ssh","ssh-config"],"created_at":"2024-08-02T01:03:08.598Z","updated_at":"2025-05-14T13:08:36.046Z","avatar_url":"https://github.com/kevinburke.png","language":"Go","funding_links":["https://github.com/sponsors/kevinburke"],"categories":["Go"],"sub_categories":[],"readme":"# ssh_config\n\nThis is a Go parser for `ssh_config` files. Importantly, this parser attempts\nto preserve comments in a given file, so you can manipulate a `ssh_config` file\nfrom a program, if your heart desires.\n\nIt's designed to be used with the excellent\n[x/crypto/ssh](https://golang.org/x/crypto/ssh) package, which handles SSH\nnegotiation but isn't very easy to configure.\n\nThe `ssh_config` `Get()` and `GetStrict()` functions will attempt to read values\nfrom `$HOME/.ssh/config` and fall back to `/etc/ssh/ssh_config`. The first\nargument is the host name to match on, and the second argument is the key you\nwant to retrieve.\n\n```go\nport := ssh_config.Get(\"myhost\", \"Port\")\n```\n\nCertain directives can occur multiple times for a host (such as `IdentityFile`),\nso you should use the `GetAll` or `GetAllStrict` directive to retrieve those\ninstead.\n\n```go\nfiles := ssh_config.GetAll(\"myhost\", \"IdentityFile\")\n```\n\nYou can also load a config file and read values from it.\n\n```go\nvar config = `\nHost *.test\n  Compression yes\n`\n\ncfg, err := ssh_config.Decode(strings.NewReader(config))\nfmt.Println(cfg.Get(\"example.test\", \"Port\"))\n```\n\nSome SSH arguments have default values - for example, the default value for\n`KeyboardAuthentication` is `\"yes\"`. If you call Get(), and no value for the\ngiven Host/keyword pair exists in the config, we'll return a default for the\nkeyword if one exists.\n\n### Manipulating SSH config files\n\nHere's how you can manipulate an SSH config file, and then write it back to\ndisk.\n\n```go\nf, _ := os.Open(filepath.Join(os.Getenv(\"HOME\"), \".ssh\", \"config\"))\ncfg, _ := ssh_config.Decode(f)\nfor _, host := range cfg.Hosts {\n    fmt.Println(\"patterns:\", host.Patterns)\n    for _, node := range host.Nodes {\n        // Manipulate the nodes as you see fit, or use a type switch to\n        // distinguish between Empty, KV, and Include nodes.\n        fmt.Println(node.String())\n    }\n}\n\n// Print the config to stdout:\nfmt.Println(cfg.String())\n```\n\n## Spec compliance\n\nWherever possible we try to implement the specification as documented in\nthe `ssh_config` manpage. Unimplemented features should be present in the\n[issues][issues] list.\n\nNotably, the `Match` directive is currently unsupported.\n\n[issues]: https://github.com/kevinburke/ssh_config/issues\n\n## Errata\n\nThis is the second [comment-preserving configuration parser][blog] I've written, after\n[an /etc/hosts parser][hostsfile]. Eventually, I will write one for every Linux\nfile format.\n\n[blog]: https://kev.inburke.com/kevin/more-comment-preserving-configuration-parsers/\n[hostsfile]: https://github.com/kevinburke/hostsfile\n\n## Sponsorships\n\nThank you very much to Tailscale and Indeed for sponsoring development of this\nlibrary. [Sponsors][sponsors] will get their names featured in the README.\n\nYou can also reach out about a consulting engagement: https://burke.services\n\n[sponsors]: https://github.com/sponsors/kevinburke\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fssh_config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinburke%2Fssh_config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fssh_config/lists"}