web-dev-qa-db-ja.com

公開鍵の指紋をauthorized_keysを入力として一覧表示できるライナーは1つありますか?

いくつかのサーバーでauthorized_keysファイルを監査し、それらを既知のAWSキーフィンガープリントと照合したいと思います。

ssh-keygen -lfファイル内のすべてのキーのフィンガープリントを改行付きのニースリストに出力するauthorized_keysを組み込んだワンライナーはありますか?

3
codecowboy

から serverfault

.bashrcで簡単に関数にすることができます。

function fingerprints() {
  local file="$1"
  while read l; do
    [[ -n $l && ${l###} = $l ]] && ssh-keygen -l -f /dev/stdin <<<$l
  done < $file
}

そして、次のことを行います。

$ fingerprints .ssh/authorized_keys
4
codecowboy

どうぞ:

    find /path/to/keys/directory -type f -name "*.pub" -exec ssh-keygen -lf {} \; | awk '{print $2}'

編集:おっと、わかりました。今すぐ入手してください。

どうぞ:

    while read line; do ssh-keygen -lf "$line"; done < <(cat authorised_keys_file)

(このファイルに1行に1つのキーがある場合)

2
tommy