~ / .ssh / authorized_keys 형식의 키를 사용하면 키 강도를 쉽게 결정할 수 있습니까? 있습니다. 불행하게도, 각 공개 키는

~ / .ssh / authorized_keys [2]에는 공개 키 목록이 포함되어 있습니다.

불행하게도, 각 공개 키는 키 강도 (비트 수)를 지정하지 않습니다.

이 파일을 한 줄씩 처리하고 키 강도를 출력 할 수있는 유틸리티가 있습니까?

에 대한 매뉴얼 페이지를 확인 ssh-keygen했지만 개인 키에서만 작동하는 것처럼 보입니다.

또한 pageant퍼티 도구에 표시된 것과 같은 방식으로 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



답변

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


답변

ssh-keygenopenssh-7.2 (현재 Fedora 및 Ubuntu Xenial에서)는 단일 파일에서 여러 키 읽기를 지원합니다. 따라서 간단하게 실행

# ssh-keygen -l -f ~/.ssh/authorized_keys
2048 SHA256:xh0IVbI... jakuje@jakuje (RSA)
2048 SHA256:xh0IVbI... jakuje@jakuje (RSA)

원하는 출력이됩니다.


답변

zsh가있는 경우이 작업을 단일 라이너로 수행 할 수 있습니다.

while read line ; do ssh-keygen -lf =(echo $line); done < .ssh/authorized_keys


답변

zsh 솔루션에서 bash 솔루션 외삽

while read line ; do ssh-keygen -l -f <(echo $line); done < .ssh/authorized_keys

/ dev / fd / 63은 공개 키 파일이 아닙니다.
/ dev / fd / 63은 공개 키 파일이 아닙니다.

거의 … 이것은 작동하지만 ssh-keygen은 생성 된 fd에서 직접 읽는 것을 좋아하지 않는 것 같습니다. <(리디렉션에 임시 파일을 사용하면 작동합니다. 왜 그렇습니까?

while read line
do
  cat > /tmp/key <(echo $line)
  ssh-keygen -l -f /tmp/key
done < .ssh/authorized_keys

1024 1f : c7 : da : ef : ff : ff : ff : ff : c8 : 77 : c6 ​​: f8 : 1f : dd : f3 : 1a / tmp / key (RSA)
3072 83 : cd : af : b4 : ff : ff : ff : ff : 02 : 30 : e7 : 1e : 47 : ed : c5 : 69 / tmp / key (RSA)

물론 더 쉽게 작성하고 행복 할 수 있습니다

while read line
do
  echo $line > /tmp/key
  ssh-keygen -l -f /tmp/key
done < .ssh/authorized_keys
rm /tmp/key


답변

authorized_keyssaravana가 만든 파일 에서 모든 지문을 나열하는 스크립트 :

#!/usr/bin/ksh

USER=`whoami`
USER_H=` lsuser -a home $USER |awk -F '=' '{print $2}'`

cat $USER_H/.ssh/authorized_keys| while read line
do
  echo $line > /tmp/finger_print
  echo "************* Key,finger print details below ***************************"

  cat /tmp/finger_print
  echo

  ssh-keygen -l -f /tmp/finger_print|grep -v not|awk '{print $1" " $2 " " $4}'
  if ssh-keygen -l -f /tmp/finger_print|grep "is not a" > /dev/null 2>&1
  then
    echo "The above key is an Invalid Key,Please correct it"
  fi

  echo "========================================================================"

  rm /tmp/finger_print
done


답변