如何显示ssh服务器可用的验证方法


$ ssh -o PreferredAuthentications=none -o NoHostAuthenticationForLocalhost=yes ssh_login
...: Permission denied (publickey,password,keyboard-interactive).

上面的命令可以测试来自ssh服务器的可用验证方法。但我不知道如何在围棋中获得相同的结果。有办法吗?

https://pkg.go.dev/golang.org/x/crypto/ssh

我认为go ssh客户端无法实现,因为相关方法都是私有的,无法创建和发送userAuthRequestMsg

ssh/client_auth第44行返回的方法变量。Go是认证方法的列表。

go ssh客户端认证的第一种方法是noneAuth,发送userAuthRequestMsg请求获取认证方法列表,然后使用config。验证为下一种方法,检查是否在methods中。

修改源代码/root/go/src/golang.org/x/crypto/ssh/client_auth.go,在第45行插入fmt.Println(methods),执行代码输出的methods为支持的认证。方法列表中22端口为linux安装的sshd, 8089端口为自己实现的ssh服务器连接协议内容。

package main
import (
"fmt"
"golang.org/x/crypto/ssh"
)
func main() {
auth("127.0.0.1:22")
auth("127.0.0.1:8089")
}
func auth(host string) {
client, err := ssh.Dial("tcp", host, &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{
ssh.Password(""),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
})
fmt.Println(host)
fmt.Println(client)
fmt.Println(err)
}
[root@izuf6b7o9hu1q8vzyvkyznz ~]# go run /tmp/03.go 
[publickey gssapi-keyex gssapi-with-mic password]
[publickey gssapi-keyex gssapi-with-mic password]
127.0.0.1:22
<nil>
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
[password publickey]
[password publickey]
127.0.0.1:8089
<nil>
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

最新更新