SSH连接失败connection reset解决办法

第一层:云控制台【安全组】

入站规则添加:

复制代码
协议:TCP
端口:22
源地址:0.0.0.0/0(你本机公网IP优先,方便更安全)
策略:允许

第二层服务器内部防火墙

复制代码
# 1.清空全部iptables规则,恢复默认放行
iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

# 2.关闭nftables(Ubuntu22.04原生防火墙,会覆盖iptables)
systemctl stop nftables
systemctl disable nftables

执行完立刻本机自测:

复制代码
ssh root@127.0.0.1

第三层:SSH 服务本身配置(sshd)

复制代码
# 确认服务运行
systemctl status ssh
# 必须看到 active (running)

# 确认22端口正在监听
ss -tlnp | grep :22
#输出必须有 0.0.0.0:22 LISTEN

# 修改ssh配置允许root密码登录
nano /etc/ssh/sshd_config

确保下面配置开启:

复制代码
PermitRootLogin yes
PasswordAuthentication yes

保存退出 Ctrl+O 回车,Ctrl+X

复制代码
systemctl restart ssh

检查 /etc/hosts.deny(tcp_wrappers 黑名单)

复制代码
cat /etc/hosts.deny
cat /etc/hosts.allow

如果/etc/hosts.deny写了ALL:ALL或者sshd: ALL,所有来源(含 127.0.0.1)全部拒绝

如果有内容,清空:

bash

复制代码
> /etc/hosts.deny

重点确认:

复制代码
PermitRootLogin yes
PasswordAuthentication yes
# 不能有 DenyUsers root  DenyGroups root
# 不能有 Match Address 把127.0.0.1拒绝

把你本机公网 IP 加入服务器远程连接白名单

Windows 浏览器打开,搜索:我的公网IP,拿到你电脑的公网 IP

编辑 hosts.allow

复制代码
nano /etc/hosts.allow

写入,替换为你自己的公网 IP:

复制代码
sshd:130.12.180.41  你的本机公网IP

保存退出 Ctrl+O 回车,Ctrl+X

systemctl restart ssh

相关推荐
我是koten1 小时前
【运维杂谈】K8s遇到Terminating的名称空间删除不了怎么办?(解决方案亲测有效)
linux·运维·服务器·云原生·kubernetes·k8s·名称空间
2601_967987379 小时前
安装 Redis 或 Redis Stack
linux·windows·redis·macos·安装
feng_you_ying_li9 小时前
linux之数据链路层
linux·网络·智能路由器
修己xj9 小时前
服务器无法解析域名?一次 DNS 配置缺失的排查与修复
运维
GeW10 小时前
高端化走到深处,是数据库和Linux的事
linux
程序员初一12 小时前
Linux 远程桌面有四种做法
linux·ssh
程序开发阿元12 小时前
1C1G 能跑什么:把留常驻服务和不留摆进一张内存表
linux·ssh
xbzb14 小时前
自定义 yum 软件源:Linux 上 createrepo,Windows 上纯 Python 也能造
linux·运维·windows·python·yum·createrepo
Android系统攻城狮15 小时前
Linux FFmpeg深度解析之avio_open调用流程与实战(三十八)
linux·运维·服务器·ffmpeg·音视频进阶·ffmpeg音视频
独隅15 小时前
WebStorm Linux 版安装实战与核心效能展示
linux·ide·webstorm