SSH into multiple VMs...

54 views
Skip to first unread message

Dhimant Patel

unread,
Mar 30, 2020, 3:34:54 AM3/30/20
to gce-discussion
Hi All,

My TEST setup:
  1. I have 8 VMs under my project.
  2. I also have one static IP assigned to one of the VM (say VM1), rest VMs (VM2-VM8) are having ephemeral IPs.
  3. I have gcloud setup on my linux machine and ssh setup to connect to static ip VM with "google_compute_engine" keys generated.
  4. I can successfully SSH in from my desktop linux instance to gcp static ip instance.
  5. I can ping rest of the VMs from gcp fine.
Question:
     I want to be able to ssh in from VM1 to rest of VMs using the same key.

How can I do this?



Thanks,
DP.

Kamelia Y

unread,
Mar 30, 2020, 2:22:26 PM3/30/20
to gce-discussion
Hi,

First you need to define the public and private key in the VM that you want to SSH from. In your use case you should define in the VM1. Then you need to add this public key into the other VMs.

Then you should connect to your VM that you want to SSH from and run the following command:

- ssh -i path-to-private-key username@external-ip

Max Illfelder

unread,
Mar 31, 2020, 12:21:32 AM3/31/20
to gce-discussion
Hi,

A simpler solution is using SSH agent forwarding - this allows you to use your configured SSH key to connect to VM1, and then connect using the same authentication with all of your other instances. You can use SSH agent forwarding by specifying the "-A" flag in your original SSH request to VM1.

You can also review the bastion host instructions here: https://cloud.google.com/compute/docs/instances/connecting-advanced#bastion_host

Max

Reply all
Reply to author
Forward
0 new messages