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

huangapple go评论164阅读模式
英文:

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

问题

当我尝试通过SSH连接到Ubuntu 22.04的gcloud实例时,出现以下错误:

Ubuntu版本:

  1. 没有可用的LSB模块。
  2. 发行商IDUbuntu
  3. 描述:Ubuntu 22.04 LTS
  4. 版本:22.04
  5. 代号:jammy

错误信息:

  1. ssh: 握手失败:ssh: 无法进行身份验证,尝试的方法为[none publickey],没有支持的方法可用

只有在使用golang的ssh模块goph时才会出现此错误,但是当我手动使用ssh -i ~/.ssh/id_rsa 34.132.133.12命令时,我可以成功进行SSH连接。

这是我的连接代码片段:

  1. func Connect(privateKey, username string, ip net.Addr) (*goph.Client, error) {
  2. // 使用私钥开始新的SSH连接。
  3. priKey, err := goph.Key(privateKey, "")
  4. if err != nil {
  5. return nil, fmt.Errorf("无法获取私钥:%v 错误:%v", privateKey, err)
  6. }
  7. c := 0
  8. for {
  9. log.Printf("SSH到:%v", ip)
  10. s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // 创建新的旋转器
  11. s.Start()
  12. time.Sleep(20 * time.Second)
  13. s.Stop()
  14. client, err := goph.NewUnknown(username, ip.String(), priKey)
  15. if err != nil {
  16. c++
  17. } else {
  18. log.Printf("已连接到:%v", ip.String())
  19. return client, nil
  20. }
  21. if c >= 3 {
  22. return nil, fmt.Errorf("无法连接到 %v,错误:%v", ip.String(), err)
  23. }
  24. }
  25. }

当我的代码运行在以下Ubuntu gCloud版本时,可以成功进行SSH连接:

  1. 没有可用的LSB模块。
  2. 发行商IDUbuntu
  3. 描述:Ubuntu 16.04.7 LTS
  4. 版本:16.04
  5. 代号:xenial

我尝试了许多解决方案,例如将私钥权限更改为600(已经设置好了)。我还尝试了其他建议,如ssh-add private key,但仍然遇到相同的问题。

我在SSH连接到两个Ubuntu版本时都运行了详细模式,并且两个操作系统都接受了公钥:

  1. debug1: 可以继续进行的身份验证方法:publickey
  2. debug1: 下一个身份验证方法:publickey
  3. debug2: 我们发送了一个公钥数据包,等待回复
  4. debug1: 服务器接受了密钥:

创建和设置此实例是使用gCloud的golang客户端完成的。似乎需要在实例中进行一些设置,因为我可以在旧的Ubuntu版本上进行SSH连接。

英文:

I'm getting the following error when I try to ssh into a Ubuntu 22.04 gcloud instance:

Ubuntu Version:

  1. No LSB modules are available.
  2. Distributor ID: Ubuntu
  3. Description: Ubuntu 22.04 LTS
  4. Release: 22.04
  5. Codename: jammy

Error:

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

This error only happens when I use the golang ssh module goph, but I'm able to ssh when ssh manually with: ssh -i ~/.ssh/id_rsa 34.132.133.12.

Here is my connect snippet:

  1. func Connect(privateKey, username string, ip net.Addr) (*goph.Client, error) {
  2. // Start new ssh connection with private key.
  3. priKey, err := goph.Key(privateKey, "")
  4. if err != nil {
  5. return nil, fmt.Errorf("Could not get privateKey: %v error: %v", privateKey, err)
  6. }
  7. c := 0
  8. for {
  9. log.Printf("Ssh to: %v", ip)
  10. s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
  11. s.Start()
  12. time.Sleep(20 * time.Second)
  13. s.Stop()
  14. client, err := goph.NewUnknown(username, ip.String(), priKey)
  15. if err != nil {
  16. c++
  17. } else {
  18. log.Printf("Connected to: %v", ip.String())
  19. return client, nil
  20. }
  21. if c >= 3 {
  22. return nil, fmt.Errorf("Could not connect to %v, error: %v", ip.String(), err)
  23. }
  24. }
  25. }

My code is able to ssh when running against this Ubuntu gCloud Version:

  1. No LSB modules are available.
  2. Distributor ID: Ubuntu
  3. Description: Ubuntu 16.04.7 LTS
  4. Release: 16.04
  5. Codename: xenial

I tried many solutions like changing the private key permission to 600 which was already setup. I also did other suggestion to ssh-add private key and still having the same issue.

Also I ran verbose when ssh into both ubuntu version and both OS accepted publickey:

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

The creation and setting up of this instance is done by using the gCloud golang client.
It seems that it is a settings that needs to be done in the instance since I'm able to ssh on older Ubuntu versions.

答案1

得分: 1

在https://github.com/melbahja/goph/issues/26上发现了一个错误。在我发布问题之前,当我搜索时,我没有意识到我开启了未解决问题的标志,所以它没有显示这个错误。所以我回去再次检查,并看到了这个问题。

我更新了所有的模块,因为我没有太多的模块,我执行了以下操作:

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

现在我能够进行ssh连接了。谢谢。

英文:

There was a bug on https://github.com/melbahja/goph/issues/26. When I searched before I posted the question, I did not realize that I left the open issue flag on, so it did not show this bug. So I went back to double-check and saw the issue.

I updated all my modules since I don't have much by doing the following:

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

Now I'm able to ssh. Thanks

huangapple
  • 本文由 发表于 2022年6月19日 06:09:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/72673084.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定