How to get the ssh keys for a new Google Compute Engine instance?

steevithak :

I'm a new Google Cloud trial user coming from the Amazon EC2 world and I'm totally baffled as to how I log in via ssh to a new Google Compute Engine VM instance.

I created a new instance via the Google Cloud web console (from a CentOS 6.x image, if that matters). I saw a blank on the creation form where I could paste in an existing ssh key but since this was my first instance, I didn't have one yet. I assumed it would take me through the key creation process like Amazon EC2 does. It didn't. It appears to have created the instance but I can't figure out how to get the ssh keys for it. The instance web page has a button that says "ssh" and it let me log in briefly via a pop-up web browser window that simulates an ssh session. However, it only let me in to a user-level account, not root. The pop-up had a menu item to change the user and I changed it to "root" after which it does nothing but generate connection errors and now I can't log into my instance at all.

I've searched but can't find any straight-forward documentation that explains this aspect of google compute instances. I've searched the web console but can't find the ssh key creation/selection mechanism, nor any way to create or download the keys for an instance.

Do I have to create my own ssh keys manually on my end and paste them into the form during creation or is there some other obvious step I'm missing?

Misha Brukman :

By default, a new Google Compute Engine (GCE) VM instance does not have SSH keys pre-assigned to it, so you cannot "retrieve" them as they don't exist—it's up to you to create them, or use a tool like gcloud (see below) which will prompt you to create them if you don't have SSH keys yet.

You have several options for connecting to your newly-created GCE VM.

One option is to connect using the "SSH" button in the Developer Console GUI next to the instance in the list of instances, which will open a browser window and a terminal session to the instance.

If you would like to connect via SSH client on the command-line, you can use gcloud tool (part of the Google Cloud SDK):

gcloud compute ssh example-instance

You can see the full set of flags and options on the gcloud compute ssh help page, along with several examples.

If you don't already have SSH keys, it will prompt you to create them and then connect to the instance. If you already have keys, you can use existing SSH keys, which it will transfer to the instance.

By default, gcloud expects keys to be located at the following paths:

  • $HOME/.ssh/google_compute_engine – private key
  • $HOME/.ssh/google_compute_engine.pub – public key

If you want to reuse keys from a different location with gcloud, consider either making symlinks or pointing gcloud there using the --ssh-key-file flag.

Note: if you don't use gcloud at all, you have to manually add the SSH keys to the instance's metadata as described in Setting up ssh keys at the instance level which you can do via gcloud or manually via Google Cloud console.

You can also create your own keys using ssh-keygen which is what gcloud will also use under the covers. You can connect to the instance using ssh directly instead of gcloud but you will need to specify extra parameters to do so:

ssh -i KEY_FILE -o UserKnownHostsFile=/dev/null \
    -o CheckHostIP=no -o StrictHostKeyChecking=no \
    USER@IP_ADDRESS

which will require the following parameters:

  • KEY_FILE – [Required] The file where the keys are stored on the computer, e.g., ~/.ssh/google_compute_engine.

  • USER – [Required] The username to log in that instance. Typically, this is the username of the local user running gcloud compute.

  • IP_ADDRESS – [Required] The external IP address of the instance.

For more details, see the SSH docs.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to get the ssh keys for a new Google Compute Engine instance?

分類Dev

Google Compute Engine: Required 'compute.zones.get' permission error

分類Dev

Allow external user to start/stop Google Compute Engine VM instance

分類Dev

Google compute engine instance start/status/stop using api

分類Dev

Installed MEAN on Google Compute Engine - but SSH directory is empty?

分類Dev

Google Compute Engine GPU

分類Dev

Allow Google Cloud Compute Engine Instance to write file to Google Storage Bucket - Python

分類Dev

how to get new instance of module

分類Dev

Google Compute Engine VPN DNS

分類Dev

Google Compute Engine - Click to Deploy

分類Dev

SSH経由でGoogle Compute Engineに接続できません

分類Dev

SSH Google Compute Engineがダウンしていますか?

分類Dev

Google Compute Engine for Web Server or App Engine

分類Dev

Why can't App Engine connect to Compute Engine VM instance?

分類Dev

What is the difference between Google App Engine and Google Compute Engine?

分類Dev

google compute engine tool gcloud is exceptionally slow

分類Dev

Removing or releasing a static IP on Google Compute Engine

分類Dev

Google Compute Engine VM constantly crashes

分類Dev

Google Compute Engine Container Port Closed

分類Dev

How to run docker in docker in Container-optimized OS on Compute Engine VM on Google Cloud?

分類Dev

How to attach a static external IP address to a google cloud compute instance using the CLI

分類Dev

Google Compute Engineでsshキーを設定するにはどうすればよいですか?

分類Dev

Google Compute Engine:SSHを閉じた後にエクスポートされた環境が失われました

分類Dev

Irssi certificate, OpenPGP and SSH keys in a new install

分類Dev

How to get an old Google App Engine SDK version

分類Dev

Google Cloud Storage、Compute Engine、InsufficientPermissionエラー

分類Dev

Google Compute Engine for WebServerまたはAppEngine

分類Dev

Google Compute Engine for WebServerまたはAppEngine

分類Dev

Google Compute Engine Free Trial Account and Enable Billing

Related 関連記事

  1. 1

    How to get the ssh keys for a new Google Compute Engine instance?

  2. 2

    Google Compute Engine: Required 'compute.zones.get' permission error

  3. 3

    Allow external user to start/stop Google Compute Engine VM instance

  4. 4

    Google compute engine instance start/status/stop using api

  5. 5

    Installed MEAN on Google Compute Engine - but SSH directory is empty?

  6. 6

    Google Compute Engine GPU

  7. 7

    Allow Google Cloud Compute Engine Instance to write file to Google Storage Bucket - Python

  8. 8

    how to get new instance of module

  9. 9

    Google Compute Engine VPN DNS

  10. 10

    Google Compute Engine - Click to Deploy

  11. 11

    SSH経由でGoogle Compute Engineに接続できません

  12. 12

    SSH Google Compute Engineがダウンしていますか?

  13. 13

    Google Compute Engine for Web Server or App Engine

  14. 14

    Why can't App Engine connect to Compute Engine VM instance?

  15. 15

    What is the difference between Google App Engine and Google Compute Engine?

  16. 16

    google compute engine tool gcloud is exceptionally slow

  17. 17

    Removing or releasing a static IP on Google Compute Engine

  18. 18

    Google Compute Engine VM constantly crashes

  19. 19

    Google Compute Engine Container Port Closed

  20. 20

    How to run docker in docker in Container-optimized OS on Compute Engine VM on Google Cloud?

  21. 21

    How to attach a static external IP address to a google cloud compute instance using the CLI

  22. 22

    Google Compute Engineでsshキーを設定するにはどうすればよいですか?

  23. 23

    Google Compute Engine:SSHを閉じた後にエクスポートされた環境が失われました

  24. 24

    Irssi certificate, OpenPGP and SSH keys in a new install

  25. 25

    How to get an old Google App Engine SDK version

  26. 26

    Google Cloud Storage、Compute Engine、InsufficientPermissionエラー

  27. 27

    Google Compute Engine for WebServerまたはAppEngine

  28. 28

    Google Compute Engine for WebServerまたはAppEngine

  29. 29

    Google Compute Engine Free Trial Account and Enable Billing

ホットタグ

アーカイブ