File: ssh-keyinfo

package info (click to toggle)
ssh-tools 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 200 kB
  • sloc: sh: 1,125; makefile: 10
file content (71 lines) | stat: -rwxr-xr-x 1,944 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash

#  +---------------------------------------------------------------------------------------------------+
#  | Title        : ssh-keyinfo                                                                        |
#  |                                                                                                   |
#  | Description  : Prints keys in several formats                                                     |
#  |                                                                                                   |
#  | Author       : Sven Wick <sven.wick@gmx.de>                                                       |
#  | URL          : https://github.com/vaporup/ssh-tools                                               |
#  |                                                                                                   |
#  +---------------------------------------------------------------------------------------------------+

# shellcheck disable=SC2207

#
# Usage/Help message
#

function usage() {

cat << EOF

    Usage: ${0##*/} FILE [...]

    Examples:

        ${0##*/} ~/.ssh/id_rsa.pub

        ${0##*/} ~/.ssh/*.pub

EOF

}

if [[ -z $1 || $1 == "--help" ]]; then
    usage
    exit 1
fi

fingerprint_hashes=( md5 sha256 )

function get_fingerprints () {

  hash_type=$1
  key_file=$2

  ssh-keygen -E "${hash_type}" -qlf "${key_file}" | while IFS= read -r line; do

    key_data=( $(printf '%s\n' "${line}") )
    key_size=${key_data[0]}
    key_hash=${key_data[1]}
    #key_comment=${key_data[2]}
    key_type=${key_data[-1]}
    key_hash_type="${key_hash%%:*}"
    key_hash_data="${key_hash#*:}"

    printf "%10s%6s%8s %-50s %s\n" "${key_type}" "${key_size}" "${key_hash_type}" "${key_hash_data}" "${key_file}"

  done

}

KEYS=( "$@" )

for KEY in "${KEYS[@]}"; do

  for fingerprint_hash in "${fingerprint_hashes[@]}"; do
    get_fingerprints "${fingerprint_hash}" "${KEY}"
  done

done