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

相关推荐
en.en..5 小时前
Linux系统编程:fcntl 与 ioctl
linux·运维·服务器
自动化监测Learner5 小时前
Navicat Premium 17 中文版安装教程(2026最新版)
java·linux·数据库
荣合技术服务6 小时前
Codex 实战:用 AI 写运维脚本
运维·codex
李昊哲小课6 小时前
Deepin 25 上安装 Docker CE 实战记录
运维·docker·容器·deepin
pingglala6 小时前
ubuntu-nat模式不能上网解决方法
linux·运维·ubuntu
一技安身7 小时前
【信创】外网aarch64终端安装deepseek Ragflow 迁移至内网银河麒麟服务器
运维·服务器
微软技术分享7 小时前
Ubuntu 本地部署Ollama+OpenWebUI教程
数据库·ubuntu·postgresql
Zixhy7 小时前
多点巡检机器人项目技术总结
linux·c++·机器人·自动驾驶
考虑考虑7 小时前
ElasticSearch索引命令
运维·后端·elasticsearch
雯宝8 小时前
7. USB 网络适配器驱动
linux