如何增加golang.org/x/crypto/ssh冗余度
我想使用golang.org/x/crypto/ssh编写一个小程序,它能够读取与ssh-v输出等效的内容。虽然我能够通过ssh包连接到服务器,但我不知道如何启用详细输出或获取其中所需的信息。由于我是刚来戈兰的新手,我甚至无法决定这是否可行 这是到目前为止我的代码如何增加golang.org/x/crypto/ssh冗余度,go,ssh,Go,Ssh,我想使用golang.org/x/crypto/ssh编写一个小程序,它能够读取与ssh-v输出等效的内容。虽然我能够通过ssh包连接到服务器,但我不知道如何启用详细输出或获取其中所需的信息。由于我是刚来戈兰的新手,我甚至无法决定这是否可行 这是到目前为止我的代码 package main import ( "fmt" "golang.org/x/crypto/ssh" ) type SSHClient struct { Config *ssh.ClientConf
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")
}
作为一种快速黑客,您可以打开
$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"))
thx对于您的快速响应,这听起来像是一个可能的解决方案,但我如何访问现在可用的调试信息?如果您运行程序,调试信息将记录在控制台上。