SSH using scala with username and password

流过昼夜 提交于 2020-01-15 10:27:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!