title: gCloud instance: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
body: <p>I'm getting the following error when I try to ssh into a Ubuntu 22.04 gcloud instance:</p>
  <p>Ubuntu Version:</p>
  <pre><code>No LSB modules are available.
  Distributor ID: Ubuntu
  Description:    Ubuntu 22.04 LTS
  Release:    22.04
  Codename:   jammy
  </code></pre>
  <p>Error:</p>
  <pre><code>ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
  </code></pre>
  <p>This error only happens when I use the golang ssh module <a href="https://github.com/melbahja/goph" rel="nofollow noreferrer">goph</a>, but I'm able to ssh when ssh manually with: <code>ssh -i ~/.ssh/id_rsa 34.132.133.12</code>.</p>
  <p>Here is my connect snippet:</p>
  <pre><code>func Connect(privateKey, username string, ip net.Addr) (*goph.Client, error) {
      // Start new ssh connection with private key.
      priKey, err := goph.Key(privateKey, &quot;&quot;)
      if err != nil {
          return nil, fmt.Errorf(&quot;Could not get privateKey: %v error: %v&quot;, privateKey, err)
      }
  
      c := 0
      for {
          log.Printf(&quot;Ssh to: %v&quot;, 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(&quot;Connected to: %v&quot;, ip.String())
              return client, nil
          }
  
          if c &gt;= 3 {
              return nil, fmt.Errorf(&quot;Could not connect to %v, error: %v&quot;, ip.String(), err)
          }
      }
  }
  </code></pre>
  <p>My code is able to ssh when running against this Ubuntu gCloud Version:</p>
  <pre><code>No LSB modules are available.
  Distributor ID: Ubuntu
  Description:    Ubuntu 16.04.7 LTS
  Release:    16.04
  Codename:   xenial
  </code></pre>
  <p>I tried many solutions like changing the private key permission to <code>600</code> which was already setup. I also did other suggestion to <code>ssh-add private key</code> and still having the same issue.</p>
  <p>Also I ran verbose when ssh into both ubuntu version and both OS accepted publickey:</p>
  <pre><code>debug1: Authentications that can continue: publickey
  debug1: Next authentication method: publickey
  debug2: we sent a publickey packet, wait for reply
  debug1: Server accepts key: 
  </code></pre>
  <p>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.</p>