~/.ssh/authorized_keys[2] 包含公钥列表。
不幸的是,每个公钥都没有指定密钥强度(位数)。
是否有可以逐行处理此文件并输出密钥强度的实用程序?
我检查了 的手册页ssh-keygen
,但它看起来只适用于私钥。
另外,是否有一种工具可以以与pageant
Putty 工具中显示的方式相同的方式输出 sha1 哈希?
我正在寻找的格式:
Key Algorithm Strength Hash Comment
ssh-rsa 2048 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff user1@host1
ssh-rsa 2048 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:11 user2@host2
Run Code Online (Sandbox Code Playgroud)
Chr*_*sen 17
ssh-keygen可以完成工作的核心(从公钥生成指纹),但它不会自动处理通常在authorized_keys
文件中找到的多个密钥列表。
这是一个拆分密钥的脚本,将它们提供给ssh-keygen并生成您想要的表:
#!/bin/sh
# usage: authkeys-report <authorized_keys-file>
set -ue
tmp="$(mktemp -t fingerprint-authkeys.XXXXXXXX)"
trap 'rm -f "$tmp"' 0
while read opts key; do
case "$opts" in
[0-9]*|ssh-dss|ssh-rsa)
# not options, first "word" is part of key
key="$opts $key"
;;
esac
echo "$key" >$tmp
set -- $(ssh-keygen -lf "$tmp")
bits="$1" fingerprint="$2"
set -- $key # Note: will mangle whitespace in the comment
case "$1" in
[0-9]*) # SSH v1 key
type=rsa1
shift 3
;;
ssh-rsa|ssh-dss) # SSH v2 key
type="$1"
shift 2
;;
*)
type=unknown
set --
;;
esac
printf '%-14s %-9s %s %s\n' "$type" "$bits" "$fingerprint" "$*"
done <$1
Run Code Online (Sandbox Code Playgroud)
Jak*_*uje 11
ssh-keygen
在 openssh-7.2(目前至少在 Fedora 和 Ubuntu Xenial 中)支持从单个文件读取多个密钥。因此运行简单
# ssh-keygen -l -f ~/.ssh/authorized_keys
2048 SHA256:xh0IVbI... jakuje@jakuje (RSA)
2048 SHA256:xh0IVbI... jakuje@jakuje (RSA)
Run Code Online (Sandbox Code Playgroud)
产生所需的输出。
如果您有 zsh,则可以单行执行此操作:
while read line ; do ssh-keygen -lf =(echo $line); done < .ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18528 次 |
最近记录: |