{"id":21749069,"url":"https://github.com/veeso/ssh2-config","last_synced_at":"2026-01-17T16:27:36.316Z","repository":{"id":57668443,"uuid":"434317664","full_name":"veeso/ssh2-config","owner":"veeso","description":"a ssh/ssh2 config parser and serializer for OpenSSH","archived":false,"fork":false,"pushed_at":"2026-01-14T10:41:02.000Z","size":184,"stargazers_count":19,"open_issues_count":0,"forks_count":15,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-16T20:11:22.019Z","etag":null,"topics":["rust","rust-crate","rust-library","ssh","ssh-config","ssh-config-parser","ssh2","ssh2-rs"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/veeso.png","metadata":{"funding":{"github":"veeso","ko_fi":"veeso"},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-12-02T17:40:35.000Z","updated_at":"2026-01-14T15:23:01.000Z","dependencies_parsed_at":"2026-01-16T08:08:41.696Z","dependency_job_id":null,"html_url":"https://github.com/veeso/ssh2-config","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"57b15ef6cb5878fe2441081835705f5e6cd3cd6b"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/veeso/ssh2-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fssh2-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fssh2-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fssh2-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fssh2-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/veeso","download_url":"https://codeload.github.com/veeso/ssh2-config/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fssh2-config/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28511864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["rust","rust-crate","rust-library","ssh","ssh-config","ssh-config-parser","ssh2","ssh2-rs"],"created_at":"2024-11-26T08:16:18.013Z","updated_at":"2026-01-17T16:27:36.270Z","avatar_url":"https://github.com/veeso.png","language":"Rust","readme":"# ssh2-config\n\n[![license-mit](https://img.shields.io/crates/l/ssh2-config.svg)](https://opensource.org/licenses/MIT)\n[![repo-stars](https://img.shields.io/github/stars/veeso/ssh2-config?style=flat)](https://github.com/veeso/ssh2-config/stargazers)\n[![downloads](https://img.shields.io/crates/d/ssh2-config.svg)](https://crates.io/crates/ssh2-config)\n[![latest-version](https://img.shields.io/crates/v/ssh2-config.svg)](https://crates.io/crates/ssh2-config)\n[![ko-fi](https://img.shields.io/badge/donate-ko--fi-red)](https://ko-fi.com/veeso)\n[![conventional-commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits\u0026logoColor=white)](https://conventionalcommits.org)\n\n[![Build](https://github.com/veeso/ssh2-config/actions/workflows/build.yml/badge.svg)](https://github.com/veeso/ssh2-config/actions/workflows/build.yml)\n[![coveralls](https://coveralls.io/repos/github/veeso/ssh2-config/badge.svg)](https://coveralls.io/github/veeso/ssh2-config)\n[![docs](https://docs.rs/ssh2-config/badge.svg)](https://docs.rs/ssh2-config)\n\n---\n\n- [ssh2-config](#ssh2-config)\n    - [About ssh2-config](#about-ssh2-config)\n        - [Exposed attributes](#exposed-attributes)\n        - [Missing features](#missing-features)\n    - [Get started 🚀](#get-started)\n        - [Reading unsupported fields](#reading-unsupported-fields)\n    - [How host parameters are resolved](#how-host-parameters-are-resolved)\n        - [Resolvers examples](#resolvers-examples)\n    - [Configuring default algorithms](#configuring-default-algorithms)\n        - [Examples](#examples)\n    - [Support the developer ☕](#support-the-developer-)\n    - [Contributing and issues 🤝🏻](#contributing-and-issues-)\n    - [Changelog ⏳](#changelog-)\n    - [License 📃](#license-)\n\n---\n\n## About ssh2-config\n\nssh2-config a library which provides a parser for the SSH configuration file, to be used in pair with\nthe [ssh2](https://github.com/alexcrichton/ssh2-rs) crate.\n\nThis library provides a method to parse the configuration file and returns the configuration parsed into a structure.\nThe `SshConfig` structure provides all the attributes which **can** be used to configure the **ssh2 Session** and to\nresolve\nthe host, port and username.\n\nOnce the configuration has been parsed you can use the `query(\u0026str)` method to query configuration for a certain host,\nbased on the configured patterns.\n\nEven if many attributes are not exposed, since not supported, there is anyway a validation of the configuration, so\ninvalid configuration will result in a parsing error.\n\n### Exposed attributes\n\n- **AddKeysToAgent**: you can use this attribute add keys to the SSH agent\n- **BindAddress**: you can use this attribute to bind the socket to a certain address\n- **BindInterface**: you can use this attribute to bind the socket to a certain network interface\n- **CASignatureAlgorithms**: you can use this attribute to handle CA certificates\n- **CertificateFile**: you can use this attribute to parse the certificate file in case is necessary\n- **Ciphers**: you can use this attribute to set preferred methods with the session method\n  `session.method_pref(MethodType::CryptCs, ...)` and `session.method_pref(MethodType::CryptSc, ...)`\n- **Compression**: you can use this attribute to set whether compression is enabled with `session.set_compress(value)`\n- **ConnectionAttempts**: you can use this attribute to cycle over connect in order to retry\n- **ConnectTimeout**: you can use this attribute to set the connection timeout for the socket\n- **ForwardAgent**: you can use this attribute to forward your agent to the remote server\n- **HostName**: you can use this attribute to get the real name of the host to connect to\n- **IdentityFile**: you can use this attribute to set the keys to try when connecting to remote host.\n- **KexAlgorithms**: you can use this attribute to configure Key exchange methods with\n  `session.method_pref(MethodType::Kex, algos.to_string().as_str())`\n- **MACs**: you can use this attribute to configure the MAC algos with\n  `session.method_pref(MethodType::MacCs, algos..to_string().as_str())` and\n  `session.method_pref(MethodType::MacSc, algos..to_string().as_str())`\n- **Port**: you can use this attribute to resolve the port to connect to\n- **ProxyJump**: you can use this attribute to specify hosts to jump via\n- **PubkeyAuthentication**: you can use this attribute to set whether to use the pubkey authentication\n- **RemoteForward**: you can use this method to implement port forwarding with `session.channel_forward_listen()`\n- **ServerAliveInterval**: you can use this method to implement keep alive message interval\n- **TcpKeepAlive**: you can use this method to tell whether to send keep alive message\n- **UseKeychain**: (macos only) used to tell whether to use keychain to decrypt ssh keys\n- **User**: you can use this method to resolve the user to use to log in as\n\n### Missing features\n\n- [Match patterns](http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5#Match) (Host patterns are supported!!!)\n- [Tokens](http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5#TOKENS)\n\n---\n\n## Get started\n\nFirst of all, add ssh2-config to your dependencies\n\n```toml\n[dependencies]\nssh2-config = \"^0.5\"\n```\n\nthen parse the configuration\n\n```rust\nuse ssh2_config::{ParseRule, SshConfig};\nuse std::fs::File;\nuse std::io::BufReader;\n\nfn main() {\n    let mut reader = BufReader::new(File::open(config_path).expect(\"Could not open configuration file\"));\n    let config = SshConfig::default().parse(\u0026mut reader, ParseRule::STRICT).expect(\"Failed to parse configuration\");\n\n    // Query attributes for a certain host\n    let params = config.query(\"192.168.1.2\");\n}\n```\n\nthen you can use the parsed parameters to configure the session:\n\n```rust\nuse ssh2::Session;\nuse ssh2_config::{HostParams};\n\nfn configure_session(session: \u0026mut Session, params: \u0026HostParams) {\n    if let Some(compress) = params.compression {\n        session.set_compress(compress);\n    }\n    if params.tcp_keep_alive.unwrap_or(false) \u0026\u0026 params.server_alive_interval.is_some() {\n        let interval = params.server_alive_interval.unwrap().as_secs() as u32;\n        session.set_keepalive(true, interval);\n    }\n    // KEX\n    if let Err(err) = session.method_pref(\n        MethodType::Kex,\n        params.kex_algorithms.algorithms().join(\",\").as_str(),\n    ) {\n        panic!(\"Could not set KEX algorithms: {}\", err);\n    }\n\n    // host key\n    if let Err(err) = session.method_pref(\n        MethodType::HostKey,\n        params.host_key_algorithms.algorithms().join(\",\").as_str(),\n    ) {\n        panic!(\"Could not set host key algorithms: {}\", err);\n    }\n\n    // ciphers\n    if let Err(err) = session.method_pref(\n        MethodType::CryptCs,\n        params.ciphers.algorithms().join(\",\").as_str(),\n    ) {\n        panic!(\"Could not set crypt algorithms (client-server): {}\", err);\n    }\n    if let Err(err) = session.method_pref(\n        MethodType::CryptSc,\n        params.ciphers.algorithms().join(\",\").as_str(),\n    ) {\n        panic!(\"Could not set crypt algorithms (server-client): {}\", err);\n    }\n\n    // mac\n    if let Err(err) = session.method_pref(\n        MethodType::MacCs,\n        params.mac.algorithms().join(\",\").as_str(),\n    ) {\n        panic!(\"Could not set MAC algorithms (client-server): {}\", err);\n    }\n    if let Err(err) = session.method_pref(\n        MethodType::MacSc,\n        params.mac.algorithms().join(\",\").as_str(),\n    ) {\n        panic!(\"Could not set MAC algorithms (server-client): {}\", err);\n    }\n}\n\nfn auth_with_rsakey(\n    session: \u0026mut Session,\n    params: \u0026HostParams,\n    username: \u0026str,\n    password: Option\u003c\u0026str\u003e\n) {\n    for identity_file in params.identity_file.unwrap_or_default().iter() {\n        if let Ok(_) = session.userauth_pubkey_file(username, None, identity_file, password) {\n            break;\n        }\n    }\n}\n\n```\n\n### Reading unsupported fields\n\nAs outlined above, ssh2-config does not support all parameters available in the man page of the SSH configuration file.\n\nIf you require these fields you may still access them through the `unsupported_fields` field on the `HostParams`\nstructure like this:\n\n```rust\nuse ssh2_config::{ParseRule, SshConfig};\nuse std::fs::File;\nuse std::io::BufReader;\n\nfn main() {\n    let mut reader = BufReader::new(File::open(config_path).expect(\"Could not open configuration file\"));\n    let config = SshConfig::default().parse(\u0026mut reader, ParseRule::ALLOW_UNSUPPORTED_FIELDS).expect(\"Failed to parse configuration\");\n\n    // Query attributes for a certain host\n    let params = config.query(\"192.168.1.2\");\n    let forwards = params.unsupported_fields.get(\"dynamicforward\");\n}\n```\n\n---\n\n## How host parameters are resolved\n\nThis topic has been debated a lot over the years, so finally since 0.5 this has been fixed to follow the official ssh\nconfiguration file rules, as described in the\nMAN \u003chttps://man.openbsd.org/OpenBSD-current/man5/ssh_config.5#DESCRIPTION\u003e.\n\n\u003e Unless noted otherwise, for each parameter, the first obtained value will be used. The configuration files contain\n\u003e sections separated by Host specifications, and that section is only applied for hosts that match one of the patterns\n\u003e given in the specification. The matched host name is usually the one given on the command line (see the\n\u003e CanonicalizeHostname option for exceptions).\n\u003e\n\u003e Since the first obtained value for each parameter is used, more host-specific declarations should be given near the\n\u003e beginning of the file, and general defaults at the end.\n\nThis means that:\n\n1. The first obtained value parsing the configuration top-down will be used\n2. Host specific rules ARE not overriding default ones if they are not the first obtained value\n3. If you want to achieve default values to be less specific than host specific ones, you should put the default values\n   at the end of the configuration file using `Host *`.\n4. Algorithms, so `KexAlgorithms`, `Ciphers`, `MACs` and `HostKeyAlgorithms` use a different resolvers which supports\n   appending, excluding and heading insertions, as described in the man page at\n   ciphers: \u003chttps://man.openbsd.org/OpenBSD-current/man5/ssh_config.5#Ciphers\u003e. They are in case appended to default\n   algorithms, which are either fetched from the openssh source code or set with a constructor.\n   See [configuring default algorithms](#configuring-default-algorithms) for more information.\n\n### Resolvers examples\n\n```ssh\nCompression yes\n\nHost 192.168.1.1\n    Compression no\n```\n\nIf we get rules for `192.168.1.1`, compression will be `yes`, because it's the first obtained value.\n\n```ssh\nHost 192.168.1.1\n    Compression no\n\nHost *\n    Compression yes\n```\n\nIf we get rules for `192.168.1.1`, compression will be `no`, because it's the first obtained value.\n\nIf we get rules for `172.168.1.1`, compression will be `yes`, because it's the first obtained value MATCHING the host\nrule.\n\n```ssh\nHost 192.168.1.1\n    Ciphers +c\n```\n\nIf we get rules for `192.168.1.1`, ciphers will be `a,b,c`, because default is set to `a,b` and `+c` means append `c` to\nthe list.\n\n---\n\n## Configuring default algorithms\n\nTo reload algos, build ssh2-config with `RELOAD_SSH_ALGO` env variable set.\n\nWhen you invoke `SshConfig::default`, the default algorithms are set from OpenSSH source code, which can be found\nhere: \u003chttps://docs.rs/ssh2_config/latest/ssh2_config/fn.default_openssh_algorithms.html\u003e.\n\nIf you want you can use a custom constructor `SshConfig::default().default_algorithms(prefs)` to set your own default\nalgorithms.\n\n---\n\n### Examples\n\nYou can view a working examples of an implementation of ssh2-config with ssh2 in the examples folder\nat [client.rs](examples/client.rs).\n\nYou can run the example with\n\n```sh\ncargo run --example client -- \u003cremote-host\u003e [config-file-path]\n```\n\n---\n\n## Support the developer ☕\n\nIf you like ssh2-config and you're grateful for the work I've done, please consider a little donation 🥳\n\nYou can make a donation with one of these platforms:\n\n[![ko-fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge\u0026logo=ko-fi\u0026logoColor=white)](https://ko-fi.com/veeso)\n[![PayPal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge\u0026logo=paypal\u0026logoColor=white)](https://www.paypal.me/chrisintin)\n\n---\n\n## Contributing and issues 🤝🏻\n\nContributions, bug reports, new features and questions are welcome! 😉\nIf you have any question or concern, or you want to suggest a new feature, or you want just want to improve ssh2-config,\nfeel free to open an issue or a PR.\n\nPlease follow [our contributing guidelines](CONTRIBUTING.md)\n\n---\n\n## Changelog ⏳\n\nView ssh2-config's changelog [HERE](CHANGELOG.md)\n\n---\n\n## License 📃\n\nssh2-config is licensed under the MIT license.\n\nYou can read the entire license [HERE](LICENSE)\n","funding_links":["https://github.com/sponsors/veeso","https://ko-fi.com/veeso","https://www.paypal.me/chrisintin"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveeso%2Fssh2-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveeso%2Fssh2-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveeso%2Fssh2-config/lists"}