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

相关推荐
H.莓飛2 分钟前
【Linux】自主 Shell
linux·运维·服务器·c语言·开发语言·visual studio
bigcarp11 分钟前
Frida-dexdump 绕过app的Root检测
linux·运维·服务器
ggaofeng11 分钟前
linux中的绿色版内存mysql
linux·运维·mysql
Lsetea13 分钟前
curl访问HTTPS报28 Operation timed out:连接超时与总超时分层排查
运维·https·ssl证书·curl·tls
草莓熊Lotso20 分钟前
【C++ 基于微服务的即时通讯系统】Elasticsearch 从安装到 C++ 客户端二次封装全落地
linux·网络·数据库·c++·elasticsearch·微服务
曦夜日长26 分钟前
主从 Reactor 高并发服务器实战 (一):前置知识与功能目标
运维·服务器
2601_9656196930 分钟前
历史解说视频怎么做:青铜器瓷器文物画面自动对齐的完整教程
运维·nginx·音视频
LiaoWL12338 分钟前
从零开始学 Linux(二):Shell 脚本入门与文本处理实战
linux·运维·服务器
.道阻且长.1 小时前
Linux软件包管理器
linux·运维·ubuntu·职场和发展·centos