<p>I am deploying a 2-node Kubernetes cluster on GCloud using kops with the following commands:</p>
<pre><code>kops create cluster part1.k8s.local --zones europe-west3-a --node-count 2 --node-image ubuntu-os-cloud/ubuntu-2004-focal-v20210129 --node-size &quot;e2-standard-2&quot; --ssh-public-key ~/.ssh/id_rsa.pub --state ${KOPS_STATE_STORE}/ --project=${PROJECT}
</code></pre>
<pre><code>kops update cluster --name part1.k8s.local --yes --admin
</code></pre>
<p>I then wait for the cluster to be ready and get the external IP of one of the nodes using:</p>
<pre><code>kubectl get nodes -o wide
</code></pre>
<p>However when I try to login to the node I get:</p>
<pre><code>ssh -i ~/.ssh/id_rsa admin@&lt;PUBLIC_IP&gt;
admin@&lt;PUBLIC_IP&gt;: Permission denied (publickey).
</code></pre>
<p>Checking the permissions the nodes should be able to accept SSH connections and I can connect to the VMs using the GCloud UI.</p>
<p>What am I doing wrong? Thanks!</p>

<p>I've encounter the issue when I tested some scenarios with <code>SSH keys</code> (add, remove, overwrite, etc).</p>
<p>When you are logging to <code>GKE</code> console, your <code>ssh keys</code> are stored in <code>~/.ssh</code>. If folder it's empty, those keys will be created ocne you will connect to VM (google_compute_engine and google_compute_engine.pub).</p>
<pre><code>$ ls ~/.ssh
google_compute_engine  google_compute_engine.pub  google_compute_known_hosts  known_hosts
</code></pre>
<p>Information about <code>SSH Key</code> is also stored in your project. You can find it in <strong>Navigation Menu</strong> &gt; <strong>Compute Engine</strong> &gt; <strong>Metadata</strong>. Next select <strong>SSH Keys tab</strong> to view instance <code>SSH keys</code>.</p>
<p>Additional information about <code>SSH Keys</code> can be found in <a href="https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys" rel="nofollow noreferrer">Managing SSH keys in metadata</a> guide.</p>
<p>If you will encounter this kind of issue, you can remove <code>SSH key</code> from UI, remove <code>google_compute_engine</code> and <code>google_compute_engine.pub</code>. While you want to <code>SSH</code> to machine, GKE will ask you to create new SSH key and issue with <code>Permission denied (publickey)</code> should be fixed.</p>
<p>Commands which should be used to <code>ssh</code> to <code>GCE</code> vm is <a href="https://cloud.google.com/sdk/gcloud/reference/compute/ssh" rel="nofollow noreferrer">gcloud ssh</a></p>
<pre><code>gcloud compute ssh &lt;instance-name&gt; --zone &lt;zone&gt;
</code></pre>
<p>Why?</p>
<blockquote>
<p>gcloud compute ssh is a thin wrapper around the ssh(1) command that takes care of authentication and the translation of the instance name into an IP address.</p>
</blockquote>
<p>In addition, if you will encounter other <code>SSH</code> issues on <code>GKE</code> you can check <a href="https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-ssh" rel="nofollow noreferrer">Troubleshooting SSH</a> guide.</p>
