You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22仍允许root用户SSH登录的问题求助

Ubuntu 22仍允许root用户SSH登录的问题求助

大家好,我碰到个棘手的问题:我在用Ubuntu 22系统,本来想通过配置SSH禁止root用户登录,但实际测试下来还是能通过SSH以root身份登录,想请教下各位大佬哪里出问题了。

我在/etc/ssh/sshd_config里手动添加了这些配置:

PasswordAuthentication no
PermitEmptyPasswords no
PubkeyAuthentication yes
PermitRootLogin no

但后来我仔细查看完整的配置文件内容,发现里面还有一行未被注释的配置:PermitRootLogin without-password,下面是配置文件的关键内容片段:

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin without-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys i...

我有点困惑,是不是因为配置文件里同时存在PermitRootLogin no和PermitRootLogin without-password导致冲突了?还是说Include引入的其他配置文件里有覆盖设置的内容?有没有大佬能帮我排查下原因?

备注:内容来源于stack exchange,提问作者itinance

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 10:08:07