如何提高golang.org/x/crypto/ssh的详细程度

i wanted to use golang.org/x/crypto/ssh to write a little program which is able to read the equivalent to ssh -v output. While i am able to connect via the ssh package to my server i have no idea how to enable verbose output or get to the desired information in it. As i am new to golang i am not even able to decide if it is possible at all.

Here is my code so far

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")
}
ssh

1个回答



作为一种快速技巧,您可以打开 $ GOPATH / golang.org / x / crypto / ssh / mux.go </ 代码>文件,将 const debugMux = false </ code>更改为 const debugMux = true </ code>并重新编译程序。</ p>

以查看调试信息 日志记录使您的程序首先执行某些操作:</ p>

  s,err:= c.NewSession()
if err!= nil {
fmt.Printf(“无法创建会话 :%s“,错误)
}
fmt.Println(s.CombinedOutput(” hostname“))
</ code> </ pre>
</ div>

展开原文

原文

As a quick hack you can open $GOPATH/golang.org/x/crypto/ssh/mux.go file, change const debugMux = false to const debugMux = true and recompile your program.

In order to see the debug logging make your program do something first:

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

douba3378
douba3378 如果运行程序,调试信息将记录在控制台上。
4 年多之前 回复
drju37335
drju37335 谢谢您的快速响应,这听起来像是一个可能的解决方案,但是我该如何访问现在可用的调试信息?
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐