Search code examples
google-cloud-platformsshgoogle-compute-engine

gcloud compute config-ssh results in permission denied


I'm trying to ssh into a gce instance:

C:\Users\Kevin>gcloud compute config-ssh
You should now be able to use ssh/scp with your instances.
For example, try running:

  $ ssh sdkmanager.us-central1-a.canigraduate-43286


C:\Users\Kevin>ssh sdkmanager.us-central1-a.canigraduate-43286
[email protected]: Permission denied (publickey).

So I guess "should" doesn't mean "can". What can I do to figure out why this doesn't work? I have OS login disabled.


Solution

  • Ok I figured out what was going on with Hector's suggestion. It turns out on Windows, gcloud generates a (I think) PuTTY-compatible RSA key instead of an OpenSSH key. That is, my private key begins with

    -----BEGIN RSA PRIVATE KEY-----
    

    On the other hand, on WSL it generates an OpenSSH private key.

    -----BEGIN OPENSSH PRIVATE KEY-----
    

    However, in Windows 10+ if you use the default ssh command without PuTTY or similar installed, it's actually an OpenSSH client, not a PuTTY client. Therefore, it will reject the key.

    If I copy the key from WSL into my C:\Users\Kevin\.ssh\ directory, overwriting the one that gcloud generates, the ssh client in Windows works.

    I'm not sure if this was intentional on gcloud's part but I guess it's expecting a different ssh client than the default one in Windows.