-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
- Loading branch information
Showing
5 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,14 @@ This makes it possible to utilize remote keys not supported by the default OpenS | |
|
||
## Example | ||
|
||
This example starts listening on a Unix socket `ssh-agent.sock` and processes requests. | ||
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`. | ||
|
||
```rust,no_run | ||
#[cfg(not(windows))] | ||
use tokio::net::UnixListener; | ||
#[cfg(windows)] | ||
use ssh_agent_lib::agent::NamedPipeListener; | ||
use ssh_agent_lib::agent::{Session, Agent}; | ||
use ssh_agent_lib::proto::message::Message; | ||
|
@@ -35,13 +39,21 @@ impl Session for MyAgent { | |
} | ||
#[tokio::main] | ||
#[cfg(not(windows))] | ||
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 | ||
MyAgent.listen(UnixListener::bind(socket)?).await?; | ||
Ok(()) | ||
} | ||
#[tokio::main] | ||
#[cfg(windows)] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
MyAgent.listen(NamedPipeListener::new(r"\\.\pipe\agent")?).await?; | ||
Ok(()) | ||
} | ||
``` | ||
|
||
Now, point your OpenSSH client to this socket using `SSH_AUTH_SOCK` environment variable and it will transparently use the agent: | ||
|
@@ -50,6 +62,12 @@ Now, point your OpenSSH client to this socket using `SSH_AUTH_SOCK` environment | |
SSH_AUTH_SOCK=ssh-agent.sock ssh [email protected] | ||
``` | ||
|
||
On Windows the path of the pipe has to be used: | ||
|
||
```sh | ||
SSH_AUTH_SOCK=\\.\pipe\agent ssh [email protected] | ||
``` | ||
|
||
For more elaborate example see the `examples` directory or [crates using `ssh-agent-lib`](https://crates.io/crates/ssh-agent-lib/reverse_dependencies). | ||
|
||
## Note | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters