Crate ssh2_config

source ·
Expand description

ssh2-config

ssh2-config a library which provides a parser for the SSH configuration file, to be used in pair with the ssh2 crate.

This library provides a method to parse the configuration file and returns the configuration parsed into a structure. The SshConfig structure provides all the attributes which can be used to configure the ssh2 Session and to resolve the host, port and username.

Once the configuration has been parsed you can use the query(&str) method to query configuration for a certain host, based on the configured patterns. Even if many attributes are not exposed, since not supported, there is anyway a validation of the configuration, so invalid configuration will result in a parsing error.

Get started

First of you need to add ssh2-config to your project dependencies:

ssh2-config = "^0.1.0"

Example

Here is a basic example:


use ssh2::Session;
use ssh2_config::{HostParams, SshConfig};
use std::fs::File;
use std::io::BufReader;
use std::path::Path;

let mut reader = BufReader::new(
    File::open(Path::new("./assets/ssh.config"))
        .expect("Could not open configuration file")
);

let config = SshConfig::default().parse(&mut reader).expect("Failed to parse configuration");

let default_params = config.default_params();
// Query parameters for your host
// If there's no rule for your host, default params are returned
let params = config.query("192.168.1.2");
Run

Structs

Enums

Type Definitions