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

相关推荐
未济5 天前
linux 配置环境变量
linux
傲世仙尊5 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
虎头金猫5 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
_艾伦 耶格尔.5 天前
进程间通信
linux
AI职业加油站5 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
Liuqy-055 天前
Linux IO编程——静态库、动态库
linux
此冬歌咏5 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
彧azz5 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅5 天前
linux(8) 软硬链接
linux·运维·服务器
AIgorithmGEEK5 天前
[Linux]线程三部曲(上):一个执行流的诞生——从操作系统一路拆到 pthread_create
linux·线程·pid