if not done already, type :
$ gcloud init
Assuming you already have ssh keys on your local workstation, create a gcloud specific one by appending your_username:
to the file. In the end it will have the following format (we'll name the file gcloud_id_rsa.pub
) :
your_username : ssh-rsa kfjdlsfjsdjklfghjkghkflkdjetc...
Then send it to gcloud :
gcloud compute project-info add-metadata --metadata-from-file sshKeys=/your/.ssh/path/gcloud_id_rsa.pub
You can then verify it has been added :
gcloud compute project-info describe
Then create your instance with the following :
gcloud compute instances create you_choose_you_instance_name --metadata-from-file startup-script=/path/to/init.sh
You can also add a specific key to a specific instance, with the following command :
gcloud compute instances add-metadata [INSTANCE_NAME] --metadata-from-file ssh-keys=[KEY_FILE_NAME].pub