问题
Is there a way we can provide username and password while doing ssh through scala code. Here is the code I am using right now but I can't figure out how to provide the user and password in the HostConfig.
SSH takes a HostConfigProvide.
https://github.com/sihil/scala-ssh
SSH("hostname") { client: SshClient =>
for {
result <- client.exec("ls -a")
} println("Result:\n" + result.stdOutAsString())
}
回答1:
I got the answer here it is.
HostConfig has the parameter login where we can define the type of the login and use any of the login type SshLogin, keyFile or PasswordLogin
SSH("hostname", HostConfig(PasswordLogin("username", PasswordProducer.fromString("password"))))
{ client: SshClient =>
for {
result <- client.exec("ls -a")
} println("Result:\n" + result.stdOutAsString())
}
来源:https://stackoverflow.com/questions/57053824/ssh-using-scala-with-username-and-password