lmrc-ssh
Part of the LMRC Stack - Infrastructure-as-Code toolkit for building production-ready Rust applications
A comprehensive Rust library for executing SSH commands programmatically. Built on top of the robust ssh2 library, lmrc-ssh provides a clean, intuitive API for managing SSH connections and executing remote commands.
Features
- 🔐 Flexible Authentication - Support for password and public key authentication
- 🚀 Simple API - Intuitive builder pattern for easy connection setup
- 📦 Batch Execution - Execute multiple commands in sequence
- 🛡️ Comprehensive Error Handling - Detailed error types with helpful messages
- 📚 Well Documented - Extensive documentation with examples
- ✅ Well Tested - Thorough test coverage
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
Password Authentication
use ;
Public Key Authentication
use ;
Usage Examples
Executing Multiple Commands
use ;
Handling Command Output
use ;
Error Handling
use ;
API Overview
SshClient
The main client for SSH connections.
new(host, port)- Create a new client instancewith_auth(auth_method)- Set the authentication methodconnect()- Establish the SSH connectionexecute(command)- Execute a single commandexecute_batch(commands)- Execute multiple commandsis_connected()- Check if the client is connected
AuthMethod
Authentication methods for SSH:
Password { username, password }- Password authenticationPublicKey { username, private_key_path, passphrase }- Public key authentication
CommandOutput
Represents the output of an executed command:
stdout- Standard outputstderr- Standard errorexit_status- Exit status codeis_success()- Check if the command succeededis_failure()- Check if the command failedcombined_output()- Get stdout + stderr combined
Error Types
Comprehensive error types for better error handling:
ConnectionFailed- Failed to establish TCP connectionAuthenticationFailed- Authentication failedExecutionFailed- Command execution failedNotConnected- Client is not connectedInvalidConfig- Invalid configuration- And more...
Examples
Check out the examples directory for more usage examples:
simple_connection.rs- Basic SSH connection and command executionbatch_commands.rs- Execute multiple commandserror_handling.rs- Comprehensive error handling examples
Run an example with:
Testing
Run the test suite:
Run tests with output:
Building Documentation
Generate and view the documentation:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Part of the LMRC Stack project. Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
This library is built on top of the excellent ssh2 crate.
Security
If you discover a security vulnerability, please email lemarc.dev@gmail.com.
Changelog
See CHANGELOG.md for release history.