简体   繁体   English

如何通过SSH连接到从自定义映像创建的GCE实例?

[英]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: 可能有用的调试问题要问自己:

  • Did you use gcimagebundle to bundle up the image or did it manually? 您是否使用gcimagebundle捆绑图像或手动完成? Consider using the tool to make sure there isn't something you missed. 考虑使用该工具确保没有您错过的东西。
  • Did you change anything about the ssh server configuration before bundling the image? 在捆绑映像之前,您是否更改了有关ssh服务器配置的任何信息?
  • When the instance is booting, check it's console output for ssh messages - it should mention regenerating the keys, starting sshd daemon and listening on port 22. If it does not or complains about something related to ssh, you should follow up on that. 当实例启动时,检查它的控制台输出ssh消息 - 它应该提到重新生成密钥,启动sshd守护进程并监听端口22.如果它没有或抱怨与ssh相关的东西,你应该跟进它。

You covered these, but for sake of completeness, these should also be checked: 你覆盖了这些,但为了完整起见,还应检查这些:

  • Can you otherwise reach the VM after it comes up? 它可以在它出现后以其他方式到达VM吗? Does it respond on webserver ports (if any) or respond to ping? 它是否响应Web服务器端口(如果有)或响应ping?
  • Double check that the network you VM is on allows SSH (port 22) access from the host you are connecting from. 仔细检查您的VM所在的网络是否允许从您连接的主机进行SSH(端口22)访问。

You can compare your ssh setup to that of a working image: 您可以将ssh设置与工作图像的设置进行比较:

  • Create a new disk (disk-mine-1) from your image. 从映像创建一个新磁盘(disk-mine-1)。
  • Create a new disk (disk-upstream-1) from any working boot image, for example the debian wheezy one. 从任何工作启动映像创建一个新磁盘(disk-upstream-1),例如debian wheezy。
  • Attach both of these to a VM you can access (either on console or from cli). 将这两者连接到您可以访问的VM(在控制台或从cli)。
  • SSH into the VM. SSH进入虚拟机。
  • Mount both of the images (sudo mkdir /mnt/{mine,upstream} && sudo mount /dev/sdb1 /mnt/mine && sudo mount /dev/sdc1 /mnt/upstream). 挂载两个映像(sudo mkdir / mnt / {mine,upstream} && sudo mount / dev / sdb1 / mnt / mine && sudo mount / dev / sdc1 / mnt / upstream)。 Note that whether your image is sdb or sdc depends on the order you attached the images! 请注意,您的图像是sdb还是sdc取决于您附加图像的顺序!
  • Look for differences between the ssh config (diff -waur /mnt/{mine,upstream}/etc/ssh). 寻找ssh配置之间的差异(diff -waur / mnt / {mine,upstream} / etc / ssh)。 There should not be any unless you specifically need them. 除非你特别需要它们,否则不应该有。
  • Also check if your image has proper /mnt/mine/etc/init.d/{ssh,generate-ssh-hostkeys} scripts. 还要检查您的图像是否具有正确的/mnt/mine/etc/init.d/{ssh,generate-ssh-hostkeys}脚本。 They should also be linked from /mnt/mine/etc/rc{S,2}.d (S10generate-ssh-hostkeys and S02ssh respectively). 它们也应该从/mnt/mine/etc/rc{S,2}.d(分别为S10generate-ssh-hostkeys和S02ssh)链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 SSH 连接之前启动 GCE 实例? - How to start a GCE instance before SSH connection? 如何从另一个gce VM切换一个gce VM - How to ssh a gce VM from another gce VM 使用操作系统登录,如何从一个 GCE 到另一个 GCE 的 gcloud ssh? - With OS login, how to gcloud ssh from one GCE into another GCE? Google Cloud Server(GCE),自定义映像,SSH登录问题 - Google Cloud server (GCE), custom image, SSH login issue 不能 ssh 进入从 sourceImage "google_compute_instance_from_machine_image" 创建的实例 - cannot ssh into instance created from sourceImage "google_compute_instance_from_machine_image" rsync ssh文件复制到GCE实例失败,权限被拒绝 - rsync ssh file copying to GCE instance fails with permission denied 通过SSH将一个GCE实例连接到另一个实例时出现问题 - Problems connecting one GCE instance to another via SSH 如何通过 FileZilla/WinScp 或 SSH 访问在 GCP 中通过市场产品部署创建的 VM 实例? - How to access an VM instance created from market product deployment in GCP via FileZilla/WinScp or SSH? GCE VM 无法通过 SSH 连接到它刚刚在不同项目中创建的新 GCE VM - GCE VM cannot SSH to the new GCE VM it has just created in a different project 无法 ssh 到从 OVA 创建的谷歌云实例 - Unable to ssh to google cloud instance which is created from the OVa
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM