在 CentOS 上“关闭 SSH 登录”有几种不同含义,下面按常见场景给你说明,你可以按需选择。
service sshd stop
chkconfig sshd off
systemctl stop sshd
systemctl disable sshd
✅ 效果:SSH 服务停止,服务器无法通过 SSH 远程登录
⚠ 注意:如果你当前是通过 SSH 登录的,执行后会被断开且无法再连回
编辑配置文件:
vi /etc/ssh/sshd_config
修改或添加:
PermitRootLogin no
重启服务:
systemctl restart sshd
在 /etc/ssh/sshd_config 中:
DenyUsers *
或
AllowUsers 空
然后重启:
systemctl restart sshd
systemctl stop firewalld
# 或
firewall-cmd --permanent --remove-service=ssh
firewall-cmd --reload
或 iptables:
iptables -A INPUT -p tcp --dport 22 -j DROP
systemctl stop sshd
(不 disable,维护完再 start)
如果你能说明是 CentOS 几 + 想达到什么目的,我可以给你更精确的命令。