Reputation: 1227
I have created two instances on Google Compute Engine:
Instance A
hostname: robot-a
ip addr: 10.111.0.11
Instance B
hostname: robot-b
ip addr: 10.222.0.22
I can log in to both instances from my local machine. But how can I log in to the other instance from one of them?
I tried the following, but failed:
robot-a$ ssh robot-b
The authenticity of host 'robot-b (10.111.0.11)' can't be established.
ECDSA key fingerprint is 3a:1a:f1:23:6a:83:ab:db:d8:a1:e8:7d:f5:65:c8:c5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'robot-b' (ECDSA) to the list of known hosts.
Permission denied (publickey).
Upvotes: 12
Views: 9796
Reputation: 11
I had the same problem. After running a number of different commands the following worked for me:
gcloud auth login <google_cloud_account>
gcloud compute ssh --zone "<vm_zone>" "<vm_name>" --internal-ip
Upvotes: 1
Reputation: 91
You need to add the public key of the machine (where you are trying to ssh from) to the the ~/.ssh/authorized_keys of the remote machine(one you are trying to connect to).
Another way is - in the GCP console - select and edit the destination machine and add the SSH key of the client machine.
Upvotes: 1
Reputation: 10058
I launched 5 new instances using Template groups, I needed to share some commands via SSH, and manually I wasnt able to connect between instances:
gcloud compute ssh rapids-instances-dj6p --zone us-central1-b
WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/google_compute_engine.
Your public key has been saved in /home/username/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:SLaTY/4PMgpzWcM/oJDnhNJq02Uqnd06ZT6ChOAnCUU username@rapids-instances-pr0c
The key's randomart image is:
+---[RSA 2048]----+
| .E |
| . |
| . o |
|o. o + + |
|= B oo% S |
| BoB**.O |
|.+*=*.B.+ |
|. o= +.* o |
| ..o o.. |
+----[SHA256]-----+
Updating project ssh metadata...⠹Updated [https://www.googleapis.com/compute/v1/projects/my-project].
Updating project ssh metadata...done.
Waiting for SSH key to propagate.
ssh: connect to host 104.155.167.207 port 22: Connection timed out
ERROR: (gcloud.compute.ssh) Could not SSH into the instance. It is possible that your SSH key has not propagated to the instance yet. Try running this command again. If you still cannot connect, verify that the firewall and instance are set to accept ssh traffic.
All these instances have Public address, gcloud ssh was trying to connect via external network, I created the following function:
function gssh() {
gcloud compute ssh $@ --internal-ip
}
And then use it like this:
gssh <hostname>
Upvotes: 1
Reputation: 1776
It's quiet simple if you have 2 instance in google cloud platform, automatically you have the guest environment installed (gcloud command lien), with it you can ssh through all you ssh inside your project:
Just run the following command line for inside your instance A to reach the Instance B
[user@Instance-A]$ gcloud compute ssh Instance-B
That it, if it's not working let me know, and verify if your firewall rule let internal traffic.
Upvotes: 0
Reputation: 939
GCE instances have gcloud set up by default. then, the easiest way to go is.
gcloud compute ssh [INSTANCE_NAME] [--ZONE [INSTANCE_ZONE]]
the zone flag might be needed because gcloud init haven't been run before in that instance.
Upvotes: 7
Reputation: 26548
See managing instance access with SSH key pairs. Basically, if you need to ssh from robot-a to robot-b, you need to generate a key pair on robot-a, add robot-a's public key to robot-b (by login to robot-b, and edit the .ssh/authorized_keys file), then robot-b recognizes robot-a.
Then access by name:
robot-a$ ssh robot-b
or by internal IP:
robot-a$ ssh 10.222.0.22
A more general help: how to set up ssh so that you are not asked for a password
Upvotes: 0