1 unstable release
Uses new Rust 2024
new 0.1.0 | May 20, 2025 |
---|
#5 in #ssh-config
10KB
128 lines
sshconfig
A Rust library for parsing SSH config files into a structured format in Rust.
Installation
Add sshconfig
crate to your cargo project:
cargo add sshconfig
Usage
Basic Usage
use sshconfig::parse_ssh_config;
use std::io;
fn main() -> io::Result<()> {
// Parse an SSH config file
let entries = parse_ssh_config("./examples/parse-ssh-config/example_config")?;
// Process the entries
for entry in entries {
println!("name: {}", entry.name);
println!("host: {}", entry.host);
println!("user: {}", entry.user);
println!("port: {}", entry.port.unwrap_or(22));
println!(
"identity file: {}",
entry.identity_file.unwrap_or("~/.ssh/id_rsa".to_string())
);
}
Ok(())
}
HostEntry Structure
Each HostEntry
object represents a Host entry in the SSH config file and contains:
name
: The host alias namehost
: The actual hostname or IP addressport
: The port number (default: 22)user
: The username (default: "root")identity_file
: The identity file path (default: "~/.ssh/id_rsa")
License
This project is licensed under the MIT or Apache-2.0 license.
Dependencies
~61KB