Friday, May 22, 2015

Connecting to your google compute instance (Google Compute, Google Cloud, SSH)

I signed up for a Google Cloud account today. I have a $300 credit or 60 days, which ever is exhausted first.

I know Amazon AWS can use Docker but I decided to go with Google Cloud because their management options for VMs seemed more complete and less shoe horned into their current offerings. In the end, I was looking for an easily manageable platform for hosting applied research backends and frontends and Google Compute looks like a great start.

So, in the process of hosting a novel Bitcoin related translation system I realized I first needed to push a custom binary to my instance. First we'll make sure ssh is set up and then we will use file-copy to push data to the instance. After some trouble shooting these are the steps I came up with:

  • 0) Go to the google compute console. Create a project and an instance. Take note of the automatically generated project-ID (this is different than the project name) and is under the Overview link under the Developers Console)
  • 1) Click on API -> Enabled APIs (in the right hand frame), make sure Google Compute is enabled
     
  • 2) Click on Google Compute -> Metadata, (right frame) SSH keys. Remove any SSH keys that are there (unless you can already ssh in and don't need to read this entry): Edit, click the X next to the key. This forces everything to start fresh.
  • 3) Open up your favorite terminal,
  • 3a) Install the gcloud SDK here
  • 3b) gcloud auth login # to authenticate your host
  • 3c) rm ~/.ssh/google-compute*; gcloud compute instances list  # identify the instance name you want to push to
  • 3d) gcloud config set project <project-ID>
  • 3e) gcloud compute ssh <instance-name> # this will create a new ssh key pair (then exit the ssh session)
  • 3f) gcloud compute copy-files <your file path> <project name>:<remote path> --zone <your zone, refer to instance list above> 
Your upload should complete and you can ssh back in to verify that the data exists.