dongren4147 2015-04-17 20:27
浏览 46
已采纳

通过外壳与SSH连接?

I am working with Go trying to automate keeping track of all of my ssh connections. I am having some issues running the command from Go. Here is my code:

cmd := exec.Command("ssh", string(c.Address))
        cmd.Stderr = os.Stderr
        cmd.Stdin = os.Stdin
        cmd.Stdout = os.Stdout
        err2 := cmd.Run()
        if err2 != nil {
            fmt.Print("Disconnected")
        }

c.Address is equivalent to "person@192.168.1.1" not using that ip obviously but when I run this I get the following error.

ssh: Could not resolve hostname 192.168.1.1
: nodename nor servname provided, or not known

I can connect just fine using ssh from my terminal.

Thanks!

  • 写回答

2条回答 默认 最新

  • duanjunjie0196 2015-12-18 07:08
    关注

    Use the golang.org/x/crypto/ssh package.

    Package documentation.

    Nice tutorial to get you started.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?