Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between the commands "gcloud compute ssh" and "ssh"

What exactly is the difference between the gcloud compute ssh comannd and "just" the ssh command?

I made the observation that even so I can easily connect between two instances using gcloud compute ssh, i cannot do it with the ssh command. However, after setting up the ssh-keys manually, the ssh command works fine. But shouldn't the gcloud command handle the key management? And if it is set up one time using gcloud, why is the ssh command not working properly

.

Works fine:

gcloud compute ssh instance_2
gcloud compute shh instance_1

.

Doesn't work without manually setting up the ssh-keys:

ssh instance_2
shh instance_1

.

This question comes from a different problem I had, which drove me nuts for days: OpenMPI: Permission denied error while trying to use mpirun

like image 846
Lodrik Avatar asked Mar 17 '16 13:03

Lodrik


People also ask

What does gcloud compute SSH do?

You use the gcloud compute ssh command to connect to your VM. Compute Engine sets a username and creates a persistent SSH key pair with the following configurations: Your username is set as the username in your local machine.

Which command do you use to connect to a running compute engine instance with SSH?

To connect to an instance without an external IP address, use the gcloud compute ssh command with the --internal-ip flag. In the Google Cloud console, go to the VM Instances page and find the internal IP address for the instance that you want to connect to.

Can you SSH into Google Cloud Shell?

The current gcloud cloud-shell command group offering provides the following functionality: Establishing an interactive SSH session with Cloud Shell using gcloud cloud-shell ssh . Copy files between your local and Cloud Shell machine via scp. Mount your Cloud Shell directory to your local file system via sshfs.


2 Answers

gcloud compute ssh installs the key pair as ~/.ssh/google_compute_engine[.pub]. ssh uses ~/.ssh/identity[.pub] by default.

You can either copy the google key pair to the default name:

$ cp ~/.ssh/google_compute_engine ~/.ssh/identity
$ cp ~/.ssh/google_compute_engine.pub ~/.ssh/identity.pub

or you can just specify the private key to use when you invoke ssh:

$ ssh -i ~/.ssh/google_compute_engine instance_name
like image 196
Mark Dame Avatar answered Sep 21 '22 12:09

Mark Dame


The dedicated google command gcloud compute ssh instance basically uses the standard ssh under the hood, but does some magic on top, e.g. installing the keys. It is quite well explained in the answer to this question: How to get the ssh keys for a new Google Compute Engine instance?

like image 30
Grzenio Avatar answered Sep 21 '22 12:09

Grzenio