如何阻止SSH回落到密码?

脚本使用SSH密钥定期启动从一台服务器到另一台服务器的SSH连接。

但是,有一次,这些密钥被简单地覆盖了。 这导致SSH客户端回退,要求input密码,这会产生不希望的连锁效应。

如果基于密钥的身份validation失败,是否可以指示SSH退出, 而不回退请求密码?

谢谢!

Wodow

如果您不希望在服务器上全局禁用密码validation,则可以在ssh命令行上使用-o "PasswordAuthentication no"选项,例如

 ssh -o "PasswordAuthentication no" YourHost 

您可以通过configurationssh守护进程来停止密码身份validation。 编辑/etc/ssh/sshd_config文件。

 #PasswordAuthentication yes 

取消注释并将上面的行更改为"no"

 PasswordAuthentication no 

不要忘记重新启动你的SSH守护进程!

vi / etc / ssh / sshd_config

# To disable tunneled clear text passwords, change to no here!

#PasswordAuthentication yes

#PermitEmptyPasswords no

PasswordAuthentication yes

yes改成no

🙂