pub struct NewSession<S: AsyncRead + AsyncWrite> { /* private fields */ }
Expand description
A newly established, unauthenticated SSH session.
All you can really do with this in authenticate it using one of the authenticate_*
methods.
You’ll most likely want NewSession::authenticate_key
.
Implementations§
Source§impl<S: AsyncRead + AsyncWrite + 'static> NewSession<S>
impl<S: AsyncRead + AsyncWrite + 'static> NewSession<S>
Sourcepub fn authenticate_key(
self,
user: &str,
key: KeyPair,
) -> Box<dyn Future<Item = Session<S>, Error = HandlerError<()>>>where
S: Tcp,
pub fn authenticate_key(
self,
user: &str,
key: KeyPair,
) -> Box<dyn Future<Item = Session<S>, Error = HandlerError<()>>>where
S: Tcp,
Authenticate as the given user using the given keypair.
Examples found in repository?
examples/ls.rs (line 25)
12fn main() {
13 // async:
14
15 let mut core = tokio_core::reactor::Core::new().unwrap();
16 let handle = core.handle();
17
18 let cmd = ::std::env::args().skip(1).next().unwrap();
19 let key = thrussh_keys::load_secret_key("/home/jon/aws-test.pem", None).unwrap();
20
21 let ls_out = TcpStream::connect(&"52.23.157.12:22".parse().unwrap(), &handle)
22 .map_err(thrussh::Error::IO)
23 .map_err(thrussh::HandlerError::Error)
24 .and_then(|c| Session::new(c, &handle))
25 .and_then(|session| session.authenticate_key("ec2-user", key))
26 .and_then(|mut session| session.open_exec(&cmd));
27
28 let channel = core.run(ls_out).unwrap();
29 let (channel, data) = core.run(tokio_io::io::read_to_end(channel, Vec::new()))
30 .unwrap();
31 println!("{}", ::std::str::from_utf8(&data[..]).unwrap());
32 let status = core.run(channel.exit_status()).unwrap();
33 println!("{}", status);
34
35 /*
36
37 // sync:
38
39 // Connect to the local SSH server
40 let tcp = TcpStream::connect("127.0.0.1:22").unwrap();
41 let mut sess = Session::new().unwrap();
42 sess.handshake(&tcp).unwrap();
43 sess.userauth_agent("username").unwrap();
44
45 let mut channel = sess.channel_session().unwrap();
46 channel.exec("ls").unwrap();
47 let mut s = String::new();
48 channel.read_to_string(&mut s).unwrap();
49 println!("{}", s);
50 channel.wait_close();
51 println!("{}", channel.exit_status().unwrap());
52 */
53}
Auto Trait Implementations§
impl<S> Freeze for NewSession<S>where
S: Freeze,
impl<S> !RefUnwindSafe for NewSession<S>
impl<S> !Send for NewSession<S>
impl<S> !Sync for NewSession<S>
impl<S> Unpin for NewSession<S>where
S: Unpin,
impl<S> !UnwindSafe for NewSession<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more