SSH-KEYGEN接受标准输入 [英] ssh-keygen accepting stdin
问题描述
我想用一个变量通过庆典
作为输入,而不是一个文件 SSH-凯基
调用获得公共密钥的指纹。我知道,我可以用一个临时文件来解决这个问题,但原因出这个问题的范围,我不想。
这个方法做的不的工作,因为它说,关键文件是无效的(这是肯定正确的)
回声$ PUBKEY | SSH-凯基-LF的/ dev /标准输入
此的确实的工作,但是没有使用一个变量,而不是一个文件。
SSH-凯基-lf alpha.pub
此的确实的工作,但是没有使用一个变量,而不是重定向的文件。
SSH-凯基-LF为/ dev /标准输入< alpha.pub
这确实的不的工作,因为我得到一个模棱两可的重定向
SSH-凯基-LF为/ dev /标准输入< $(回声$ PUBKEY)
我想AP preciate一些有识之士就如何获得SSH-凯基从变量与公用密钥,如果可能的阅读,解释,为什么重定向没有做什么,我想他们应该是这样做。在具体为什么 |
行为与不同的<
,为什么第三个例子是一个暧昧重定向
。我在网上搜但是很多重定向教程似乎没有回答我的问题。
回声$ PUBKEY | SSH-凯基-LF的/ dev /标准输入
为/ dev /标准输入不是一个公钥文件。
为/ dev /标准输入实际上是一个UNIX管道,而不是一个普通的文件,所以SSH-凯基无法打开文件
SSH-凯基-LF为/ dev /标准输入<<< $关键
1024 92:6A:3F:5C:1F:78:.....
为/ dev /标准输入指的是普通文件,通过使用一个bash定界符创建的。您可以验证这一点:
#ls -l命令的/ dev /标准输入<<< $ PUBKEY
lrwxrwxrwx 1根根11年2月15日08:07为/ dev /标准输入 - >的/ proc /自/ FD / 0
#ls -l命令的/ proc /自/ FD / 0℃;<< $ PUBKEY
LR-X ------ 1尤尔根克林斯曼64年04月14 13:31的/ proc /自/ FD / 0 - >的/ tmp / SH-THD-1271250023(删除)
I am trying to call ssh-keygen
using a variable through bash
as an input instead of a file to get a fingerprint of a public key. I am aware that I could use a temp file to get around this issue, but for reasons out of scope of this question, I do not want to.
This method does not work as it says the key file is invalid (it's correct for sure)
echo $pubkey | ssh-keygen -lf /dev/stdin
This does work, but is not using a variable, rather a file.
ssh-keygen -lf alpha.pub
This does work, but is not using a variable, rather a redirected file.
ssh-keygen -lf /dev/stdin < alpha.pub
This does not work because I get an ambiguous redirect
ssh-keygen -lf /dev/stdin < $(echo $pubkey)
I would appreciate some insight as to how to get ssh-keygen to read from a variable with a public key and if possible, an explanation as to why the redirects aren't doing what I think they should be doing. In specific why the |
behaves differently than the <
and why the third example is an ambiguous redirect
. I searched online but many of the redirect tutorials didn't seem to answer my questions.
echo $pubkey | ssh-keygen -lf /dev/stdin
/dev/stdin is not a public key file.
/dev/stdin is actually a unix pipe, not a regular file, so ssh-keygen fails to open the file
ssh-keygen -lf /dev/stdin <<<$key
1024 92:6a:3f:5c:1f:78:.....
/dev/stdin refers to a regular file, created by using a bash heredoc. You can verify this:
# ls -l /dev/stdin <<<$pubkey
lrwxrwxrwx 1 root root 15 Feb 11 08:07 /dev/stdin -> /proc/self/fd/0
# ls -l /proc/self/fd/0 <<<$pubkey
lr-x------ 1 juergen juergen 64 Apr 14 13:31 /proc/self/fd/0 -> /tmp/sh-thd-1271250023 (deleted)
这篇关于SSH-KEYGEN接受标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!