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

I am a new Google Cloud user coming from the Amazon EC2 world, and I am completely puzzled by how I log in via ssh to a new instance of VM Engine Engine Engine.

I created a new instance through the Google Cloud web console (if that matters from the CentOS 6.x image). I saw a space in the creation form where I could insert the existing ssh key, but since this was my first instance, I did not have it yet. I assumed that this would lead me to a key creation process like Amazon EC2. This is not true. It seems he created an instance, but I cannot figure out how to get ssh keys for it. There is a button with the message “ssh” on the instance web page, and it allows me to log in through a pop-up web browser window that simulates an ssh session. However, it allows me to log in to the account at the user level, and not in the root folder. The popup menu had a menu item to change the user, and I changed it to root, after which it does nothing,except for connection errors, and now I can’t log into my instance at all.

I searched but cannot find direct documentation that explains this aspect of Google instances. I searched the web console, but I cannot find the mechanism for creating / selecting the ssh key and in no way create or load keys for the instance.

Do I need to manually create my own ssh keys at my end and paste them into the form during creation, or is there some other obvious step that I am missing?

+39
source share
5 answers

Google Compute Engine (GCE) SSH, "" , - , , gcloud (. ), , SSH.

GCE.

"SSH" GUI , .

SSH- , gcloud ( Google Cloud SDK):

gcloud compute ssh example-instance

gcloud compute ssh, .

SSH, , . , SSH-, .

gcloud , :

  • $HOME/.ssh/google_compute_engine -
  • $HOME/.ssh/google_compute_engine.pub -

gcloud, gcloud --ssh-key-file.

:, gcloud, SSH , ssh ​​ , gcloud Google Cloud console.

, ssh-keygen, gcloud . ssh gcloud, :

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

:

  • KEY_FILE - [] , , ~/.ssh/google_compute_engine.

  • USER - [] . , , gcloud compute.

  • IP_ADDRESS - [] IP- .

. SSH.

+54

ssh- [ , Linux Ubuntu 16.04]

  1. SSH ssh-keygen -t rsa -f ~/.ssh/gcloud_instance1 -C varunon9 gcloud_instance1 - , varunon9 -

  2. cd ~/.ssh && cat gcloud_instance1.pub

  3. enter image description here.

  4. ( cd ~/.ssh && cat gcloud_instance1.pub) ssh-

    enter image description here enter image description here

  5. ssh ssh -i gcloud_instance1 varunon9@35.200.201.56 gcloud_instance1 - ( .ssh), varunon9 - , 35.200.201.56 - IP- .

+12

ssh :

1: putty puttyGen https://putty.org/

2: / ( Windows 10 Linux Linux)

: ssh-keygen

: , google_key

2 google_key google_key.pub

3. google_key.pub.

, . .

4. Compute Engine →

"SSH " " SSH"

google_key.pub. , . .

5: Google Compute.

IP vm_instance_external_ip

Linux

ssh -i google_key.pub username @vm_instance_external_ip

""

.

,

+2

, gcloud ssh. gcloud .

gcloud compute --project ssh --zone

And if this is the first time, it will create an ssh key for you. You just need to download the file at this location ~ / .ssh / google_compute_engine using the gcloud client file download option in the upper right corner. Once you have the key file, just enter

ssh -i username @external_IP

+1
source

I found a useful button that helps to avoid guessing games for various gcloud parameters like versionId, serviceId etc.

View gcloud command -> ssh screenshot

0
source

All Articles