aboutsummaryrefslogtreecommitdiffstats
path: root/sshfprs.sh
blob: a0aaabe8eb51d5037848f3b5f8bab631de0cf0dd (plain)
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
#!/bin/sh

# Like ssh-keygen -lf, but for a file such as authorized_keys, which
# may contain multiple keys.
#
# Usage: sshfprs.sh file [prefix]
#
#
# Copyright 2013 Guilhem Moulin <guilhem@fripost.org>
#
# Licensed under the GNU GPL version 3 or higher.

set -ue

file="$1"
prefix="${2:-}"

while read pk; do
	# ssh-keygen can't read from STDIN, and ash doesn't have the '<<<'
	# construct, so we save each pubkey in a temporary file
	pkf=$(mktemp)
	echo "$pk" > "$pkf"
	echo "${prefix}$(ssh-keygen -lf $pkf)"
	rm "$pkf"
done < "$file"