6 releases

0.4.0 Mar 25, 2024
0.3.0 Feb 27, 2024
0.2.7 Feb 16, 2024
0.2.5 May 10, 2022
0.2.3 Mar 28, 2022

#56 in Authentication

Download history 156/week @ 2024-02-12 10/week @ 2024-02-19 198/week @ 2024-02-26 25/week @ 2024-03-04 62/week @ 2024-03-11 45/week @ 2024-03-18 227/week @ 2024-03-25 137/week @ 2024-04-01

475 downloads per month
Used in 2 crates

MIT license

1.5K SLoC


CI Crates.io

A collection of types for writing custom SSH agents as specified by the SSH Agent Protocol Internet Draft.

This makes it possible to utilize remote keys not supported by the default OpenSSH agent.


The following example starts listening on a socket and processing requests. On Unix it uses ssh-agent.sock Unix domain socket while on Windows it uses a named pipe \\.\pipe\agent.

use tokio::net::UnixListener;
use ssh_agent_lib::agent::NamedPipeListener;

use ssh_agent_lib::agent::{Session, Agent};
use ssh_agent_lib::proto::message::Message;

struct MyAgent;

impl Session for MyAgent {
    async fn handle(&mut self, message: Message) -> Result<Message, Box<dyn std::error::Error>> {
        match message {
            Message::SignRequest(request) => {
                // get the signature by signing `request.data`
                let signature = vec![];
            _ => Ok(Message::Failure),

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let socket = "ssh-agent.sock";
    let _ = std::fs::remove_file(socket); // remove the socket if exists


async fn main() -> Result<(), Box<dyn std::error::Error>> {

Now, point your OpenSSH client to this socket using SSH_AUTH_SOCK environment variable and it will transparently use the agent:

SSH_AUTH_SOCK=ssh-agent.sock ssh user@example.com

On Windows the path of the pipe has to be used:

SSH_AUTH_SOCK=\\.\pipe\agent ssh user@example.com

For more elaborate example see the examples directory or crates using ssh-agent-lib.


This library has been forked from sekey/ssh-agent.rs as the upstream seems not be maintained (at least as of 2022).


This project is licensed under the MIT license.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you shall be licensed as above, without any additional terms or conditions.


~100K SLoC