如何增加golang.org/x/crypto/ssh详细程度

时间:2016-02-17 07:31:42

标签: go ssh

我想用golang.org/x/crypto/ssh编写一个能够读取ssh -v输出等效的小程序。虽然我能够通过ssh包连接到我的服务器,但我不知道如何启用详细输出或获取其中所需的信息。由于我是golang的新手,我甚至无法决定它是否可行。

到目前为止,这是我的代码

package main

import (
    "fmt"

    "golang.org/x/crypto/ssh"
)

type SSHClient struct {
    Config *ssh.ClientConfig
    Host   string
    Port   int
}

func main() {
    sshConfig := &ssh.ClientConfig{
        User: "your_user_name",
        Auth: []ssh.AuthMethod{
            ssh.Password("your_password"),
        },
    }

    client := &SSHClient{
        Config: sshConfig,
        Host:   "example.com",
        Port:   22,
    }

    client.test()
    _, err := ssh.Dial("tcp", "example.com:22", sshConfig)
    if err != nil {
        fmt.Printf("Failed to dial: %s", err)
    }

}

func (client *SSHClient) test() {
    fmt.Println("test")
}

1 个答案:

答案 0 :(得分:1)

作为快速黑客,您可以打开$GOPATH/golang.org/x/crypto/ssh/mux.go文件,将const debugMux = false更改为const debugMux = true并重新编译您的程序。

为了看到调试日志记录,让你的程序先做一些事情:

s, err := c.NewSession()
if err != nil {
    fmt.Printf("Failed to create session: %s", err)
}
fmt.Println(s.CombinedOutput("hostname"))
相关问题