大网数据广告活动
服务器运维问答

Google Compute Engine ssh: connect to host <IP> port 22: Operation timed out

· 52CE 我爱测

I have setup my VM on Google compute engine and connect to it from my Mac using SSH via Gcloud. I have installed my Django website and after that when I run the command below: sudo ufw enable After this command I not able to conn…

问题原文

原帖链接 · Abdul Rehman · CC BY-SA 4.0

I have setup my VM on Google compute engine and connect to it from my Mac using SSH via Gcloud. I have installed my Django website and after that when I run the command below:

sudo ufw enable

After this command I not able to connect to my VM instance vis SSH, I need to edit some of my files for my site but I'm not able to connect to my instance.

When I run the command below:

gcloud compute --project "GCP_Project" ssh --zone "my_zone" "Instane_Name"

I got the error below:

ssh: connect to host <my_ip> port 22: Operation timed out
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

I don't know, how can I fix this issue.

Thanks in advance!

已采纳解答

原帖链接 · Milad Tabrizi · CC BY-SA 4.0

When you turn UFW on, denies any incoming connection. So, you need to disable it for port 22 and then you will be SSH to your machine again. To do so, you should edit your instance and run a Startup Script.

  1. In the GCP Console, go to the VM Instances page.

  2. Select the instance and click edit.

  3. Find Custom metadata option and Click Add item and Type Startup-script as a key and Copy and past the command sudo ufw allow ssh as a value. This command will enabled port 22 for SSH.

  4. Click save

  5. Stop and start the instance. After rebooting the instance you should be able to SSH again.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。