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
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.
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.
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.
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With