-
Notifications
You must be signed in to change notification settings - Fork 0
/
exos_ssh_key_fingerprint.sh
executable file
·34 lines (29 loc) · 1.32 KB
/
exos_ssh_key_fingerprint.sh
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
#! /bin/bash
# exos_ssh_key_fingerprint.sh - compute fingerprint for ExtremeXOS SSH key.
# Copyright (C) 2018-2022 Erik Auerswald <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -u
test "$#" -eq 1 ||
{ echo 'Usage: exos_ssh_key_fingerprint.sh FILENAME'; exit 1; }
umask 0077
TDIR="$(mktemp -d "exos_ssh_key_fingerprint.$$.XXXXXXXXXX")" ||
{ echo 'ERROR: could not create temporary directory'; exit 1; }
trap "rm -rf \"$TDIR\"" 0
tr -dc '[:xdigit:]' < "$1" | xxd -p -r > "$TDIR/key.ascii"
fgrep -i encrypted "$TDIR/key.ascii" >/dev/null 2>&1 &&
{ echo 'ERROR: SSH key is encrypted'; exit 1; }
chmod 600 "$TDIR/key.ascii"
ssh-keygen -y -f "$TDIR/key.ascii" > "$TDIR/pubkey"
ssh-keygen -l -f "$TDIR/pubkey" | cut -d' ' -f2