Crates.io | sshkit_rs |
lib.rs | sshkit_rs |
version | 0.1.0 |
source | src |
created_at | 2023-04-04 02:26:10.531544 |
updated_at | 2023-04-04 02:26:10.531544 |
description | A Rust library to execute commands on remote hosts using SSH |
homepage | https://github.com/MonkeyDLabs/sshkit.rs |
repository | https://github.com/MonkeyDLabs/sshkit.rs |
max_upload_size | |
id | 829720 |
size | 52,923 |
SSHKit.rs is a Rust library, inspired by the ruby version. SSHKit.rs provides an easy-to-use interface for interacting with remote servers over SSH. It is designed to simplify common SSH operations, such as executing commands, uploading and downloading files, and managing connections to remote hosts.
The library aims to be simple, yet powerful, providing a high-level interface for performing complex tasks, while still being easy to use for developers who are new to Rust or SSH programming. It is built on top of the popular SSH2 library, which provides a solid foundation for secure and reliable SSH communication.
One of the major benefits of using SSHKit.rs is its asynchronous design, which allows for multiple connections to be managed simultaneously, greatly increasing performance and scalability. Additionally, it provides a flexible and extensible architecture that can be easily customized to fit specific use cases or requirements.
Overall, SSHKit.rs is a valuable tool for developers who need to perform remote operations over SSH, whether it be for automated deployments, configuration management, or other use cases.
Here are some examples of how you can use SSHKit.rs:
let sshkit = SshKit::new();
let server = Host::new("127.0.0.1", "killix", None).with_password("password");
let cmd = CommandBuilder::new("ls -la");
let exec_mode = ExecMode::Sequential(Some(Duration::from_secs(5)));
let results = sshkit.on(server.clone()).execute(cmd, exec_mode).await?;
for result in results {
for (host, output) in result {
println!("Output from {}: {:?}", host.address, output);
}
}
let cmd = CommandBuilder::new("printenv")
.add_command("ls -la /etc")
let cmd = CommandBuilder::new("printenv")
.with_env("VAR1", "value1")
.with_env("VAR2", "value2");
let cmd = CommandBuilder::new("printenv")
.with_in("/remote/path")
let cmd = CommandBuilder::new("printenv")
.as_user("admin")
let sshkit = SshKit::new();
let server = Host::new("127.0.0.1", "killix", None).with_password("password");
let file_opts = FileOptions::new("/path/to/remote/file").with_local_path("/path/to/local/file", );
ssh_kit
.on(server)
.upload(file_opts);
let sshkit = SshKit::new();
let server = Host::new("127.0.0.1", "killix", None).with_password("password");
let file_opts = FileOptions::new("/path/to/remote/file").with_local_path("/path/to/local/file", );
ssh_kit
.on(server)
.download(file_opts);
let sshkit = SshKit::new();
let server = Host::new("127.0.0.1", "killix", None).with_password("password");
let cmd = CommandBuilder::new("node -v");
let exec_mode = ExecMode::Sequential(None);
let results = sshkit.on(server.clone()).test(cmd, exec_mode).await?;
for result in results {
for (host, output) in result {
println!("Output from {}: {:?}", host.address, output);
}
}
The ExecMode enum defines the different modes of execution for running commands on multiple hosts. It has three variants:
SSHKit.rs utilizes a simple connection pool to reduce the overhead of negotiating new SSH connections. By default, if a connection hasn't been used for more than 30 seconds, it will be replaced with a new one. This timeout can be customized for each server.
Contributions to SSHKit.rs are welcome and appreciated! To contribute, please follow these steps:
Before submitting a pull request, please ensure that your code follows Rust coding standards and that all tests are passing. Additionally, if you are introducing new features, please update the documentation and examples accordingly.
We look forward to collaborating with you on this project!
SSHKit.rs is released under the MIT License.