gCloud instance: ssh: handshake failed: ssh: able to authent



当我尝试ssh到Ubuntu 22.04 gcloud实例时,我得到以下错误:

Ubuntu版本:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy

错误:

ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

此错误仅在我使用golang ssh模块goph时发生,但我可以在手动ssh时使用:ssh -i ~/.ssh/id_rsa 34.132.133.12.

下面是我的连接代码片段:
func Connect(privateKey, username string, ip net.Addr) (*goph.Client, error) {
// Start new ssh connection with private key.
priKey, err := goph.Key(privateKey, "")
if err != nil {
return nil, fmt.Errorf("Could not get privateKey: %v error: %v", privateKey, err)
}
c := 0
for {
log.Printf("Ssh to: %v", ip)
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
s.Start()
time.Sleep(20 * time.Second)
s.Stop()
client, err := goph.NewUnknown(username, ip.String(), priKey)
if err != nil {
c++
} else {
log.Printf("Connected to: %v", ip.String())
return client, nil
}
if c >= 3 {
return nil, fmt.Errorf("Could not connect to %v, error: %v", ip.String(), err)
}
}
}

我的代码能够ssh运行在这个Ubuntu gCloud版本:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.7 LTS
Release:    16.04
Codename:   xenial

我尝试了许多解决方案,如将私钥权限更改为已经设置的600。我也给ssh-add private key做了其他建议,仍然有同样的问题。

当ssh到ubuntu版本和两个操作系统都接受publickey时,我也运行了verbose:

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: 

这个实例的创建和设置是通过使用gCloud golang客户机完成的。这似乎是一个需要在实例中完成的设置,因为我能够在旧版本的Ubuntu上ssh。

https://github.com/melbahja/goph/issues/26有一个bug。当我在发布问题之前搜索时,我没有意识到我留下了开放问题标志,所以它没有显示这个错误。于是我又回去复查,发现了问题所在。

我更新了我所有的模块,因为我没有做以下的事情:

go get -u ./...
go mod tidy

现在我可以ssh了。由于