[英]How to SSH into a GCE Instance created from a custom image?
I'm having issues using ssh to log in to a VM created from a custom image. 我在使用ssh登录到从自定义映像创建的VM时遇到问题。
I followed the steps for creating an image from an existing GCE instance . 我按照从现有GCE实例创建图像的步骤进行操作。
I have successfully created the image, uploaded it to Google Cloud Storage and added it as an image to my project, yet when I try to connect to the new image, I get a "Connection Refused". 我已经成功创建了图像,将其上传到Google Cloud Storage并将其作为图像添加到我的项目中,但是当我尝试连接到新图像时,我收到了“拒绝连接”。
I can see other applications running on other ports for the new image, so it seems to be just ssh that is affected. 我可以看到其他端口上运行的其他应用程序用于新映像,因此它似乎只是受影响的ssh。
The steps I did are below: 我做的步骤如下:
...create an image from existing GCE instance (one I can log into fine via ssh)..then:
gcutil --project="river-ex-217" addimage example2 http://storage.googleapis.com/example-image/f41aca6887c339afb0.image.tar.gz
gcutil --project="river-ex-217" addinstance --image=example2 --machinetype=n1-standard-1 anothervm
gcutil --service_version="v1" --project="river-ex-217" ssh --zone="europe-west1-a" "anothervm"
Which outputs: 哪个输出:
INFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/mark1/.ssh/google_compute_engine -A -p 22 mark1@23.251.133.2 --
ssh: connect to host 23.251.133.2 port 22: Connection refused
I've tried deleting the sshKeys metadata as suggested in another SO answer, and reconnecting which did this: 我已经尝试删除另一个SO答案中建议的sshKeys元数据,并重新连接,这样做:
INFO: Updated project with new ssh key. It can take several minutes for the instance to pick up the key.
INFO: Waiting 120 seconds before attempting to connect.
INFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/mark1/.ssh/google_compute_engine -A -p 22 mark1@23.251.133.2 --
ssh: connect to host 23.251.133.2 port 22: Connection refused
I then try for the first instance in another zone, it works fine with the new key: 然后我尝试在另一个区域中的第一个实例,它与新密钥一起正常工作:
gcutil --service_version="v1" --project="river-ex-217" ssh --zone="europe-west1-b" "image1"
Both instances are running on the same "default" network with port 22 running, and ssh works for the first instance the image is created from. 这两个实例都在运行端口22的同一“默认”网络上运行,而ssh适用于创建映像的第一个实例。
I tried nc command from the other instance and my local machine, it shows no output: 我从其他实例和我的本地机器尝试了nc命令,它没有输出:
nc 23.251.133.2 22
...whilst the original VM's ip shows this output: ...虽然原始VM的ip显示此输出:
nc 192.157.29.255 22
SSH-2.0-OpenSSH_6.0p1 Debian-4
I've tried remaking the image again and re-adding the instance, no difference. 我已经尝试重新制作图像并重新添加实例,没有区别。
I've tried logging in to the first instance, and switching user to one on that machine (which should be the same as the second machine?), and ssh from there. 我已经尝试登录到第一个实例,并将用户切换到该机器上的一个(应该与第二台机器相同?),并从那里开始ssh。
WARNING: You don't have an ssh key for Google Compute Engine. Creating one now...
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
INFO: Updated project with new ssh key. It can take several minutes for the instance to pick up the key.
INFO: Waiting 300 seconds before attempting to connect.
INFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /home/mark/.ssh/google_compute_engine -A -p 22 mark@23.251.133.2 -- --zone=europe-west1-a
ssh: connect to host 23.251.133.2 port 22: Connection refused
I'm out of ideas, any help greatly appreciated :) The maddening thiing is I can see the new VM is live with the application ready, I just need to add a few files to it and set up some cronjobs. 我没有想法,任何帮助都非常感激:)令人抓狂的事情是,我可以看到新的VM已经准备就绪应用程序,我只需要添加一些文件并设置一些cronjobs。 I guess I could do this pre-image making, but I would like to be able to log in at a later date and modify it, without needing to take 1hr to create images and launch new instances every time.
我想我可以做这个预图像制作,但我希望能够在以后登录并修改它,而不需要花费1小时来创建图像并每次都启动新的实例。
Yours faithfully, Mark 你的忠实,马克
This question appears to be about how to debug SSH connectivity problems with images, so here is my answer to that. 这个问题似乎是关于如何调试图像的SSH连接问题,所以这是我的答案。
It appears that your instance may not be running the SSH server properly. 您的实例可能未正确运行SSH服务器。 There may be something amiss with the prepared image.
准备好的图像可能有些不对劲。
Possibly useful debugging questions to ask yourself: 可能有用的调试问题要问自己:
You covered these, but for sake of completeness, these should also be checked: 你覆盖了这些,但为了完整起见,还应检查这些:
You can compare your ssh setup to that of a working image: 您可以将ssh设置与工作图像的设置进行比较:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.