gpt4 book ai didi

ssh - 戈朗 : Execute shell commands on remote server

转载 作者:IT王子 更新时间:2023-10-29 01:33:49 27 4
gpt4 key购买 nike

我有 50 台左右的 Linux 机器 (RHEL)。我想通过在中央机器上运行的 go 脚本在这些机器上运行一些命令。我已经为从中央机器到所有远程机器的所有人设置了无密码 ssh 身份验证。尽管我也对非 ssh 解决方案持开放态度,但首选安全的解决方案。

正在运行的命令会随着时间而改变。我还想在中央机器上运行的脚本中处理在远程机器上运行的命令的输出和返回代码。

我只找到这个 ssh package ,仅支持密码认证方式,不够好。

还有其他选择吗?

最佳答案

你可以使用这个包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)
}
}

关于ssh - 戈朗 : Execute shell commands on remote server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26434759/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com