您如何要求用户使用密钥认证登录?

您如何要求用户使用密钥认证登录?

我已经创建了一个新用户并为他们生成了一个安全验证在我的本地机器上输入密钥并设法将公钥内容复制到ssh/authorized_key服务器中的该用户目录中。

但不知何故,该用户无需密钥即可登录。即ssh newuser@localhost。他们还可以使用登录ssh -i "keyname" newuser@localhost

答案1

!!!! 仅当您确实想要禁用 SSH 守护进程的密码登录时才执行此操作!!!!

为了使其正常工作,您必须告诉 ssh 守护程序您不需要密码,只有当我们知道密钥登录完全可行时才应该这样做:

您必须编辑此文件:

/etc/ssh/sshd_config 

并更改以下值:

原来的:

RSAAuthentification yes

应该:

RSAAuthentification no

原来的:

#AuthorizedKeysFile %h/.ssh/authorized_keys

应该:

AuthorizedKeysFile %h/.ssh/authorized_keys

原来的:

#IgnoreUserKnowHosts yes
ChallengeResponseAuthentication yes
PasswordAuthentication yes

应该:

IgnoreUserKnowHosts yes
ChallengeResponseAuthentication no
PasswordAuthentication no

最后重新启动 sshd 守护进程:

/etc/init.d/ssh restart

相关内容