golang:在远程服务器上执行shell命令
问题描述:
我有50台Linux机器(RHEL)。我想通过在中央机器上运行的go脚本在这些机器上运行一些命令。我从中央机器到所有远程机器都设置了无密码ssh认证。虽然我也对非ssh解决方案开放,尽管安全是首选。golang:在远程服务器上执行shell命令
正在运行的命令会随着时间而改变。我也想处理在中央机器上运行的脚本中的远程机器上运行的命令的输出和返回代码。
我只发现这ssh package,它只支持密码验证方法,这是不够好的。
还有其他的选择吗?
答
您可以使用公钥与go.crypto/ssh
包使用PublicKeys
。
有使用ssh剂@https://github.com/davecheney/socksie/blob/master/main.go在repo详细示例围绕线114
又如。
答
你只可以使用此包https://github.com/hypersleep/easyssh
例如,您可以远程调用ps ax
:
package main
import (
"fmt"
"github.com/hypersleep/easyssh"
)
func main() {
ssh := &easyssh.MakeConfig {
User: "core",
Server: "core",
Key: "/.ssh/id_rsa",
Port: "22",
}
response, err := ssh.Run("ps ax")
if err != nil {
panic("Can't run remote command: " + err.Error())
} else {
fmt.Println(response)
}
}
所以这是一个文档错误即可。 :)'目前只有 //支持“密码”验证方法 – Kashyap 2014-10-18 19:36:27