Skip to main content

AgentService

Struct AgentService 

Source
pub struct AgentService<'a> { /* private fields */ }
Expand description

SSH agent operations.

Obtained from SshManager::agent().

Implementations§

Source§

impl<'a> AgentService<'a>

Source

pub fn new(paths: &'a SshPaths, runner: &'a dyn CliRunner) -> Self

Source

pub async fn status(&self) -> Result<bool>

Check if the SSH agent is reachable.

Returns true when SSH_AUTH_SOCK points to an existing socket and we can successfully connect to the agent.

§Errors

Returns an error if the agent check command itself fails unexpectedly (not merely because the agent is unavailable).

Source

pub async fn list_keys(&self) -> Result<Vec<SshKey>>

List all keys currently loaded in the SSH agent.

§Errors

Returns Error::AgentNotAvailable if the agent is not running, or Error::AgentOperationFailed if the agent protocol fails.

Source

pub async fn add_key(&self, key_path: &Path) -> Result<()>

Add a private key to the SSH agent.

§Errors

Returns Error::AgentOperationFailed if the key cannot be added (e.g. passphrase required, agent rejects the key).

Source

pub async fn remove_key(&self, key_path: &Path) -> Result<()>

Remove a key from the SSH agent.

§Errors

Returns Error::AgentOperationFailed if the key cannot be removed.

Source

pub async fn test_key_usability(&self, key_path: &Path) -> Result<bool>

Test whether a key is usable by the SSH agent (ssh-add -T).

Returns true if the key is usable (already decrypted/loaded or accessible via hardware token), false otherwise.

§Errors

Returns Error::AgentOperationFailed if the test command itself cannot be executed.

Source

pub async fn destination_constrained_add( &self, key_path: &Path, hosts: &[&str], ) -> Result<()>

Add a key restricted to specific destination hosts (ssh-add -h).

The key will only be authorized for connections to the listed hosts. At least one host must be provided.

§Errors

Returns Error::AgentOperationFailed if hosts is empty or if the command fails.

Source

pub async fn remove_all(&self) -> Result<()>

Remove all keys from the SSH agent (ssh-add -D).

Returns the number of keys removed (best-effort; some agents don’t report count).

§Errors

Returns Error::CommandFailed if the command fails.

Source

pub async fn add_key_with_lifetime( &self, key_path: &Path, lifetime_seconds: u32, ) -> Result<()>

Add a key to the SSH agent with a lifetime limit (ssh-add -t).

lifetime_seconds specifies how long the key should remain loaded.

§Errors

Returns Error::CommandFailed if the key cannot be added or the lifetime argument is invalid.

Source

pub async fn add_key_with_confirmation(&self, key_path: &Path) -> Result<()>

Add a key to the SSH agent with confirmation required (ssh-add -c).

The agent will request user confirmation each time the key is used.

§Errors

Returns Error::CommandFailed if the key cannot be added.

Source

pub async fn add_key_with_passphrase( &self, key_path: &Path, passphrase: &str, ) -> Result<()>

Add a passphrase-protected key to the SSH agent using SSH_ASKPASS.

This creates a temporary askpass script that supplies the passphrase non-interactively, which is useful when loading keys from a TUI or other automated context where terminal input is not available.

The temporary script is cleaned up automatically when this method returns (on success or failure).

§Errors

Returns Error::CommandFailed if the key cannot be added, or Error::Io if the temporary askpass script cannot be created.

Source

pub async fn list_sessions(&self) -> Result<Vec<ControlSession>>

List active ControlMaster sessions.

Scans for control socket files in the SSH directory and /tmp, verifying each is still alive.

§Errors

Returns Error::TaskFailed if the background scan task panics or is cancelled.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for AgentService<'a>

§

impl<'a> !UnwindSafe for AgentService<'a>

§

impl<'a> Freeze for AgentService<'a>

§

impl<'a> Send for AgentService<'a>

§

impl<'a> Sync for AgentService<'a>

§

impl<'a> Unpin for AgentService<'a>

§

impl<'a> UnsafeUnpin for AgentService<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more