SSH - PasswordAuthentication no 无效

SSH - PasswordAuthentication no 无效

我正在尝试配置我的服务器以禁用密码验证,我现在正在使用密钥。

问题是PasswordAuthentication no设置了,但没有效果。即使设置了,系统仍提示我输入密码。

更多细节:

  • 我正在从 Windows 10 上的 PuTTY 连接到 Ubuntu Server 14.04。
  • ssh -v显示首先使用我的键,然后使用键盘交互。
  • 我确定我已编辑sshd_config,不是ssh_config
  • 应用更改后我重新启动了ssh,但没有效果,我重新启动了整个服务器,但仍然没有效果。
  • 我有这个完全相同的配置文件在另一台 14.04 服务器上完全相同的密钥,但它没有问题并且密码验证在那里被禁用。

为什么密码验证没有被禁用,我该如何修复它?

为简洁起见,这是整个sshd_config文件减去所有注释行。

Port 612
Protocol 2
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key

KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group1-sha1
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected]

UsePrivilegeSeparation yes

KeyRegenerationInterval 3600
ServerKeyBits 1024

SyslogFacility AUTH
LogLevel INFO

LoginGraceTime 120
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes

IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no

PermitEmptyPasswords no

PasswordAuthentication no

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes

AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

UsePAM yes

答案1

问题是,使用的密码验证PAM(与所有现代系统一样)是由ChallengeResponseAuthentication选项处理的,这是yes默认的。

质询响应认证

指定是否允许质询-响应身份验证(例如通过 PAM)。默认为“是”。

例子中多次提到了这一点sshd_config

# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.

将其添加到您的sshd_config值中no,重新启动,它就会为您工作:

ChallengeResponseAuthentication no

答案2

根据 Linux 发行版,如果您使用的是 Ubuntu 22,请尝试以下操作:

sshd -T | grep passwordauthentication       

如果你看到输出passwordauthentication yes,则某些配置是在默认 /etc/ssh/sshd_config 之前设置的,它们位于/etc/ssh/sshd_config.d/,你可以passwordauthentication从中搜索,或者简单地通过以下方式删除它们:

rm /etc/ssh/sshd_config.d/*

答案3

我犯了一个愚蠢的错误(并且花了一段时间才意识到)是,sshd_config我没有编辑而是在编辑ssh_config,这就是更改没有达到预期效果的原因。

答案4

就我而言,在 Raspberry Pi 4 上全新安装的 Ubuntu Server 中,所有更改sshd_config均未生效。清除openssh-server并重新安装解决了这个问题。

参考命令:

apt purge openssh-server
rm -rf /etc/ssh (may be necessary if using apt remove)
apt install openssh-server

相关内容