Rust implementation of ssh2.0 client.
If you encounter any problems in use, welcome issues or PR .
- ssh-rs ✨
- Content
- Connection method:
- Enable global logging:
- Set timeout:
- How to use:
- Algorithm support:
- 1. Kex algorithms
- 2. Server host key algorithms
- 3. Encryption algorithms (client to server)
- 4. Encryption algorithms (server to client)
- 5. Mac algorithms (client to server)
- 6. Mac algorithms (server to client)
- 7. Compression algorithms (client to server)
- 8. Compression algorithms (server to client)
- ☃️ Additional algorithms will continue to be added.
use ssh_rs::ssh;
let mut session = ssh::create_session()
.username("ubuntu")
.password("password")
.connect("127.0.0.1:22")
.unwrap();
- Currently, only RSA, ED25519 keys/key files are supported.
// pem format key path -> /xxx/xxx/id_rsa
// the content of the keyfile shall begin with
// -----BEGIN RSA PRIVATE KEY----- / -----BEGIN OPENSSH PRIVATE KEY-----
// and end with
// -----END RSA PRIVATE KEY----- / -----END OPENSSH PRIVATE KEY-----
// simply generated by `ssh-keygen -t rsa -m PEM -b 4096`
use ssh_rs::ssh;
let mut session = ssh::create_session()
.username("ubuntu")
.private_key_path("./id_rsa")
.connect("127.0.0.1:22")
.unwrap();
// pem format key string:
// -----BEGIN RSA PRIVATE KEY----- / -----BEGIN OPENSSH PRIVATE KEY-----
// and end with
// -----END RSA PRIVATE KEY----- / -----END OPENSSH PRIVATE KEY-----
use ssh_rs::ssh;
let mut session = ssh::create_session()
.username("ubuntu")
.private_key("rsa_string")
.connect("127.0.0.1:22")
.unwrap();
- According to the implementation of OpenSSH, it will try public key first and fallback to password. So both of them can be provided.
use ssh_rs::ssh;
let mut session = ssh::create_session()
.username("username")
.password("password")
.private_key_path("/path/to/rsa")
.connect("127.0.0.1:22")
.unwrap();
-
There are two APIs to enable logs, basicly
enable_log()
will set the log level toINFO
, anddebug()
will set it toDebug
-
But you can implement your own logger as well.
use ssh_rs::ssh;
// this will generate some basic event logs
ssh::enable_log();
// this will generate verbose logs
ssh::debug()
- Only global timeouts per r/w are currently supported.
use ssh_rs::ssh;
ssh::debug();
let _listener = TcpListener::bind("127.0.0.1:7777").unwrap();
match ssh::create_session()
.username("ubuntu")
.password("password")
.private_key_path("./id_rsa")
.timeout(Some(std::time::Duration::from_secs(5)))
.connect("127.0.0.1:7777")
{
Err(e) => println!("Got error {}", e),
_ => unreachable!(),
}
- Examples can be found under examples
- Execute a command
- Scp files
- Run a shell
- Run an interactive shell
- Connect ssh server w/o a tcp stream
- Cofigure your own algorithm list
curve25519-sha256
ecdh-sha2-nistp256
diffie-hellman-group14-sha256
diffie-hellman-group14-sha1
diffie-hellman-group1-sha1
(behind feature "dangerous-dh-group1-sha1")
ssh-ed25519
rsa-sha2-256
rsa-sha2-512
rsa-sha
(behind feature "dangerous-rsa-sha1")
chacha20-poly1305@openssh.com
aes128-ctr
chacha20-poly1305@openssh.com
aes128-ctr
aes192-ctr
aes256-ctr
hmac-sha2-256
hmac-sha2-512
hmac-sha1
hmac-sha2-256
hmac-sha2-512
hmac-sha1
none
none