0

I have several Google Compute Engine (GCE) instances up and running. I have a few scripts that pull information (log files, etc) from these instances, and a few others that push up files. I would like to automate more of this, but every time I connect to a compute engine instance I need to enter my password.

How do I setup rsync or ssh so I do not need a passoword, or alternatively, how do I feed my password into those programs?

Note that this was originally posted to SO but then moved over here.

speedplane
  • 1,601

1 Answers1

1

GCE ssh uses public key authentication, not passwords, so you have the following options:

  1. use gcloud compute copy-files as described in this answer. This is likely easier as it will allow you to specify projects and host names symbolically, as the IP addresses may change.

  2. use sftp as described in this answer, namely:

    sftp -o IdentityFile ~/.ssh/google_compute_engine user@host
    
  3. use ssh but with a full path to the key file registered with GCE. This command is printed out when you run gcloud compute ssh <instance> so you can just copy-paste it and use it later. It should resemble the following:

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

    Note that here you will have to use exact IP addresses here, so consider either using static IP addresses or DNS to create a constant name for possibly-varying IP addresses (if you're using dynamic IPs).

    You can read more in the documentation.

Misha Brukman
  • 581
  • 5
  • 17