@@ -48,6 +48,7 @@ pub struct SessionBuilder {
4848 compression : Option < bool > ,
4949 jump_hosts : Vec < Box < str > > ,
5050 user_known_hosts_file : Option < Box < Path > > ,
51+ ssh_auth_sock : Option < Box < Path > > ,
5152}
5253
5354impl Default for SessionBuilder {
@@ -64,6 +65,7 @@ impl Default for SessionBuilder {
6465 compression : None ,
6566 jump_hosts : Vec :: new ( ) ,
6667 user_known_hosts_file : None ,
68+ ssh_auth_sock : None ,
6769 }
6870 }
6971}
@@ -189,6 +191,17 @@ impl SessionBuilder {
189191 self
190192 }
191193
194+ /// Specify the path to the ssh-agent.
195+ ///
196+ /// The path provided may use tilde notation (`~`) to refer to the user's
197+ /// home directory.
198+ ///
199+ /// The default is `None`.
200+ pub fn ssh_auth_sock ( & mut self , ssh_auth_sock : impl AsRef < Path > ) -> & mut Self {
201+ self . ssh_auth_sock = Some ( ssh_auth_sock. as_ref ( ) . to_owned ( ) . into_boxed_path ( ) ) ;
202+ self
203+ }
204+
192205 /// Connect to the host at the given `host` over SSH using process impl, which will
193206 /// spawn a new ssh process for each `Child` created.
194207 ///
@@ -341,6 +354,10 @@ impl SessionBuilder {
341354 init. arg ( "-o" ) . arg ( format ! ( "Compression={}" , arg) ) ;
342355 }
343356
357+ if let Some ( ssh_auth_sock) = self . ssh_auth_sock . as_deref ( ) {
358+ init. env ( "SSH_AUTH_SOCK" , ssh_auth_sock) ;
359+ }
360+
344361 let mut it = self . jump_hosts . iter ( ) ;
345362
346363 if let Some ( jump_host) = it. next ( ) {
0 commit comments