公钥认证的bash / SSH测试 [英] bash/ssh test for public key authentication
问题描述
有没有一种方法以编程方式测试SSH是否能够使用公钥验证?我愿做这样的事情(preferably在bash,但我开到一个python溶液):
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"
其中, SSH-测试啄
返回一个非零退出状态,如果在远程主机上没有公钥匹配。
where ssh-test-thingy
returns a non-zero exit status if no public key matches on the remote host.
推荐答案
我想通过选项 -o批处理模式= YES
来ssh和看看是否能工程。这将禁用提示输入密码,我想这是在实践中等同于你的愿望,以找出是否通过密钥验证是可能的。 SSH-测试啄
可以写成像这样一个bash脚本:
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:
exec ssh -o BatchMode=yes "$@" true
这只会转嫁给用户@主机(以及任何其他参数),并尝试运行真正
远程主机,如果它的工作将立即返回其上成功的状态code(0)。
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).
这篇关于公钥认证的bash / SSH测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!