[英]gcloud compute ssh from one VM to another VM on Google Cloud
I am trying to ssh into a VM from another VM in Google Cloud using the gcloud compute ssh
command.我正在尝试使用
gcloud compute ssh
命令从 Google Cloud 中的另一个 VM ssh 到 VM。 It fails with the below message:它失败并显示以下消息:
/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/compute/lib/base_classes.py:9: DeprecationWarning: the sets module is deprecated
import sets
Connection timed out
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255]. See https://cloud.google.com/compute/docs/troubleshooting#ssherrors for troubleshooting hints.
I made sure the ssh keys are in place but still it doesn't work.我确保 ssh 密钥已到位,但仍然无法正常工作。 What am I missing here?
我在这里缺少什么?
There is an assumption that you have connected to the externally-visible instance using SSH beforehand with gcloud.假设您已事先通过 gcloud 使用 SSH 连接到外部可见的实例。
From your local machine, start ssh-agent with the following command to manage your keys for you:在您的本地机器上,使用以下命令启动 ssh-agent 来管理您的密钥:
me@local:~$ eval `ssh-agent`
Call ssh-add to load the gcloud compute public keys from your local computer into the agent, and use them for all SSH commands for authentication:调用 ssh-add 将 gcloud 计算公钥从本地计算机加载到代理中,并将它们用于所有 SSH 命令以进行身份验证:
me@local:~$ ssh-add ~/.ssh/google_compute_engine
Log into an instance with an external IP address while supplying the -A argument to enable authentication agent forwarding.使用外部 IP 地址登录实例,同时提供 -A 参数以启用身份验证代理转发。
gcloud compute ssh --ssh-flag="-A" INSTANCE
source: https://cloud.google.com/compute/docs/instances/connecting-to-instance#sshbetweeninstances .来源: https : //cloud.google.com/compute/docs/instances/connecting-to-instance#sshbetweeninstances 。
I am not sure about the 'flags' because it's not working for me bu maybe I have a different OS or Gcloud version and it will work for you.我不确定“标志”,因为它对我不起作用,但也许我有不同的操作系统或 Gcloud 版本,它对你有用。
Here are the steps I ran on my Mac to connect to the Google Dataproc master VM and then hop onto a worker VM from the master MV.以下是我在 Mac 上运行以连接到 Google Dataproc 主虚拟机,然后从主 MV 跳转到工作虚拟机的步骤。 I ssh'd to the master VM to get the IP.
我通过 ssh 连接到主 VM 以获取 IP。
$ gcloud compute ssh cluster-for-cameron-m Warning: Permanently added '104.197.45.35' (ECDSA) to the list of known hosts.
I then exit
ed.然后我
exit
ed。 I enabled forwarding for that host.我为该主机启用了转发。
$ nano ~/.ssh/config
Host 104.197.45.35 ForwardAgent yes
I added the gcloud key.我添加了 gcloud 密钥。
$ ssh-add ~/.ssh/google_compute_engine
I then verified that it was added by listing the key fingerprints with ssh-add -l
.然后我通过使用
ssh-add -l
列出密钥指纹来验证它是否已添加。 I reconnected to the master VM and ran ssh-add -l
again to verify that the keys were indeed forwarded.我重新连接到主 VM 并再次运行
ssh-add -l
以验证密钥确实已转发。 After that, connecting to the worker node worked just fine.之后,连接到工作节点工作得很好。
ssh cluster-for-cameron-w-0
About using SSH Agent Forwarding...关于使用 SSH 代理转发...
Because instances are frequently created and destroyed on the cloud, the (recreated) host fingerprint keeps changing.由于实例在云上频繁创建和销毁,(重新创建的)主机指纹不断变化。 If the new fingerprint doesn't match with
~/.ssh/known_hosts
, SSH automatically disables Agent Forwarding.如果新指纹与
~/.ssh/known_hosts
不匹配,SSH 会自动禁用代理转发。 The solution is:解决办法是:
$ ssh -A -o UserKnownHostsFile=/dev/null ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.