SSH 使用带有用户名和密码的 Scala
SSH using scala with username and password
有没有一种方法可以在通过 scala 代码执行 ssh 时提供用户名和密码。
这是我现在正在使用的代码,但我不知道如何在 HostConfig 中提供用户和密码。
SSH 采用 HostConfigProvide。
SSH("hostname") { client: SshClient =>
for {
result <- client.exec("ls -a")
} println("Result:\n" + result.stdOutAsString())
}
我在这里得到了答案。
HostConfig 有参数登录,我们可以在其中定义登录类型并使用任何登录类型 SshLogin、keyFile 或 PasswordLogin
SSH("hostname", HostConfig(PasswordLogin("username", PasswordProducer.fromString("password"))))
{ client: SshClient =>
for {
result <- client.exec("ls -a")
} println("Result:\n" + result.stdOutAsString())
}
有没有一种方法可以在通过 scala 代码执行 ssh 时提供用户名和密码。 这是我现在正在使用的代码,但我不知道如何在 HostConfig 中提供用户和密码。
SSH 采用 HostConfigProvide。
SSH("hostname") { client: SshClient =>
for {
result <- client.exec("ls -a")
} println("Result:\n" + result.stdOutAsString())
}
我在这里得到了答案。
HostConfig 有参数登录,我们可以在其中定义登录类型并使用任何登录类型 SshLogin、keyFile 或 PasswordLogin
SSH("hostname", HostConfig(PasswordLogin("username", PasswordProducer.fromString("password"))))
{ client: SshClient =>
for {
result <- client.exec("ls -a")
} println("Result:\n" + result.stdOutAsString())
}