Skip to main content

SshSession

Struct SshSession 

Source
pub struct SshSession { /* private fields */ }
Expand description

An authenticated SSH session ready for command execution.

Holds the russh client handle for the duration of its lifetime. Drop → the connection is cleaned up by russh’s internal tasks.

Wrapped in Arc to allow sharing across multiple operations (discovery + metrics).

Implementations§

Source§

impl SshSession

Source

pub async fn connect(host: &Host) -> Result<Self>

Connect and authenticate to host.

Authentication is attempted in order:

  1. SSH agent (unix only, via SSH_AUTH_SOCK).
  2. Identity file specified in the host config (identity_file).
  3. Default key files (~/.ssh/id_ed25519, id_rsa, etc.).
  4. Password (if provided in host config).

Returns an error when no method succeeds or the connection times out.

§Errors
  • Connection timeout (> 10 s)
  • Authentication failure
  • Network error
Source

pub async fn run_command(&self, cmd: &str) -> Result<String>

Execute a shell command on the remote host and return its stdout.

A new SSH channel is opened for each call so sessions can be reused across multiple commands. The remote exit status is ignored — use SshSession::run_command_checked when it carries the result.

§Errors

Returns an error on channel failure or if the command times out (30 s).

Source

pub async fn run_command_checked(&self, cmd: &str) -> Result<String>

Like SshSession::run_command but returns an error when the remote command exits with a non-zero status. Use for test-style probes whose exit code is the answer (e.g. sudo -n true).

§Errors

As SshSession::run_command, plus a non-zero remote exit status.

Source

pub async fn open_sftp_channel(&self) -> Result<ChannelStream<Msg>>

Opens a new SSH channel, requests the SFTP subsystem, and returns the channel as an async stream suitable for russh_sftp::client::SftpSession::new.

The SshSession must remain alive for the entire lifetime of the SFTP session — dropping it closes the underlying TCP connection.

§Errors

Returns an error if the channel cannot be opened or if the server rejects the SFTP subsystem request.

Source

pub async fn disconnect(self)

Gracefully close the SSH connection.

Trait Implementations§

Source§

impl Clone for SshSession

Source§

fn clone(&self) -> SshSession

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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