SSH 使用带有用户名和密码的 scala [英] SSH using scala with username and password

查看:77
本文介绍了SSH 使用带有用户名和密码的 scala的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在通过 Scala 代码执行 ssh 时提供用户名和密码.这是我现在正在使用的代码,但我不知道如何在 HostConfig 中提供用户和密码.

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 需要一个 HostConfigProvide.

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())
  }

推荐答案

我在这里得到了答案.

HostConfig 有参数 login,我们可以在其中定义登录类型并使用任何登录类型 SshLogin、keyFile 或 PasswordLogin

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())
      }

这篇关于SSH 使用带有用户名和密码的 scala的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆