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

Google compute - SSH - port 22 blocked by ufw

· 52CE 我爱测

Well, I was doing some server setup reading this article and ran the following commands - sudo apt-get install ufw sudo ufw enable sudo ufw allow 80/tcp sudo ufw allow 443/tcp This basically closed all other ports and now SSH is …

问题原文

原帖链接 · A G · CC BY-SA 4.0

Well, I was doing some server setup reading this article and ran the following commands -

sudo apt-get install ufw
sudo ufw enable

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

This basically closed all other ports and now SSH is not working at all. From the browser or from osx terminal.

I have connected via serial login and can see ufw blocking connections -

[ 1292.322021] [UFW BLOCK] IN=eth0 OUT= MAC=... SRC=00.00.00.00 DST=10.142.0.2 LEN=60 TOS=0x00 PREC=0x00 TTL=45 ID=7906 PROTO=TCP SPT=58028 DPT=22 WINDOW=60720 RES=0x00 SYN URGP=0

Is there any way to ssh now as I am unable to access the machine at all.

已采纳解答

原帖链接 · Jason · CC BY-SA 4.0

By Default, all ports are blocked other than port 22 to allow you to ssh to the VM instance. You also have the option to open port 80 and/or 443. You can see which ports are open by default by checking the Firewall rules within the Cloud Console. I am mentioning this to inform you that you do not need to install ufw in the future.

You will have to provide a startup script to the VM instance to enable SSH. You can just create a simple bash script with either command listed below.

$ufw allow ssh

or

ufw allow 22

You do not have to use the sudo prefix since the startup script runs as root already.

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

资料来源与适用范围

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

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

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