bash/ssh 测试公钥身份验证
有没有办法以编程方式测试 ssh 是否可以使用公钥进行身份验证?我想做这样的事情(最好在 bash 中,但我对 python 解决方案持开放态度):
ssh-test-thingy user@host || echo "could not authenticate using publickey"
如果远程上没有公钥匹配,则 ssh-test-thingy 返回非零退出状态主持人。
Is there a way to programmatically test whether ssh can authenticate using a public key? I would like to do something like this (preferably in bash, but am open to a python solution):
ssh-test-thingy user@host || echo "could not authenticate using publickey"
where ssh-test-thingy
returns a non-zero exit status if no public key matches on the remote host.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将选项
-o BatchMode=yes
传递给 ssh 并查看是否有效。它将禁用输入密码的提示,我认为这在实践中相当于您想了解是否可以通过密钥进行身份验证。ssh-test-thingy
可以编写为 bash 脚本,如下所示:这将简单地传递 user@host (以及任何其他参数),并尝试运行
true
在远程主机上,如果有效,将立即返回成功状态代码 (0)。I'd pass the option
-o BatchMode=yes
to ssh and see if that works. It will disable prompting for a password, which I think is equivalent in practice to your desire to find out if authentication via keys is possible.ssh-test-thingy
could be written as a bash script like so:This will simply pass the user@host (and any other arguments) along, and try to run
true
on the remote host, which if it works will immediately return a status code of success (0).