Replies: 2 comments 9 replies
-
My SSH user and password are stored in the database. How can I convert the data into the required parameters for 'distance ssh2' in MySshAuthHandler |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hey there! Your password will be requested within the
async fn on_authenticate(&self, event: SshAuthEvent) -> io::Result<Vec<String>> {
trace!("[local] on_authenticate({event:?})");
let task = tokio::task::spawn_blocking(move || {
if !event.username.is_empty() {
eprintln!("Authentication for {}", event.username);
}
if !event.instructions.is_empty() {
eprintln!("{}", event.instructions);
}
let mut answers = Vec::new();
for prompt in &event.prompts {
// Contains all prompt lines including same line
let mut prompt_lines = prompt.prompt.split('\n').collect::<Vec<_>>();
// Line that is prompt on same line as answer
let prompt_line = prompt_lines.pop().unwrap();
// Go ahead and display all other lines
for line in prompt_lines.into_iter() {
eprintln!("{line}");
}
let answer = if prompt.echo {
eprint!("{prompt_line}");
std::io::stderr().lock().flush()?;
let mut answer = String::new();
std::io::stdin().read_line(&mut answer)?;
answer
} else {
rpassword::prompt_password(prompt_line)?
};
answers.push(answer);
}
Ok(answers)
});
task.await
.map_err(|x| io::Error::new(io::ErrorKind::Other, x))?
} Just force the passwordasync fn on_authenticate(&self, event: SshAuthEvent) -> io::Result<Vec<String>> {
let mut answers = Vec::new();
if event.username.is_some() && event.username.unwrap() == "name" {
// Fill in password for each prompt
for prompt in &event.prompts {
answers.push(String::from("password"));
}
Ok(answers)
} else {
// Unknown user (or maybe default if username not provided)
Err(io::Error::new(io::ErrorKind::Other, "Unknown user"))
}
} |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Can you improve the document or provide a demo?
Beta Was this translation helpful? Give feedback.
All reactions