@@ -48,6 +48,7 @@ pub struct SessionBuilder {
48
48
compression : Option < bool > ,
49
49
jump_hosts : Vec < Box < str > > ,
50
50
user_known_hosts_file : Option < Box < Path > > ,
51
+ ssh_auth_sock : Option < Box < Path > > ,
51
52
}
52
53
53
54
impl Default for SessionBuilder {
@@ -64,6 +65,7 @@ impl Default for SessionBuilder {
64
65
compression : None ,
65
66
jump_hosts : Vec :: new ( ) ,
66
67
user_known_hosts_file : None ,
68
+ ssh_auth_sock : None ,
67
69
}
68
70
}
69
71
}
@@ -189,6 +191,17 @@ impl SessionBuilder {
189
191
self
190
192
}
191
193
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
+
192
205
/// Connect to the host at the given `host` over SSH using process impl, which will
193
206
/// spawn a new ssh process for each `Child` created.
194
207
///
@@ -341,6 +354,10 @@ impl SessionBuilder {
341
354
init. arg ( "-o" ) . arg ( format ! ( "Compression={}" , arg) ) ;
342
355
}
343
356
357
+ if let Some ( ssh_auth_sock) = self . ssh_auth_sock . as_deref ( ) {
358
+ init. env ( "SSH_AUTH_SOCK" , ssh_auth_sock) ;
359
+ }
360
+
344
361
let mut it = self . jump_hosts . iter ( ) ;
345
362
346
363
if let Some ( jump_host) = it. next ( ) {
0 commit comments