homelab infrastructure services
1#!/bin/bash
2# tin key list - List all NAS servers with SSH keys
3
4set -euo pipefail
5
6# Get tinsnip root and source libraries
7SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8TINSNIP_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
9source "$TINSNIP_ROOT/lib/core.sh"
10source "$TINSNIP_ROOT/lib/registry.sh"
11
12# List all NAS servers with SSH keys
13list_nas_keys() {
14 check_tinsnip_station || return 1
15
16 log_with_prefix "SSH Keys" "NAS servers with SSH keys:"
17 echo
18
19 local ssh_keys_dir="$NAS_CREDENTIALS_DIR/ssh-keys"
20 local found_keys=false
21
22 if [[ ! -d "$ssh_keys_dir" ]]; then
23 echo "No SSH keys directory found."
24 echo "Generate keys with: tin key generate <nas-server>"
25 return 0
26 fi
27
28 for key_file in "$ssh_keys_dir"/*.key; do
29 if [[ -f "$key_file" ]]; then
30 local nas_server=$(basename "$key_file" .key)
31 local pub_key="${key_file}.pub"
32
33 echo " $nas_server"
34 echo " Private key: $key_file"
35 if [[ -f "$pub_key" ]]; then
36 echo " Public key: $pub_key"
37 local fingerprint=$(ssh-keygen -lf "$pub_key" 2>/dev/null | awk '{print $2}' || echo 'invalid')
38 echo " Fingerprint: $fingerprint"
39 else
40 echo " Public key: ❌ MISSING"
41 fi
42 echo
43 found_keys=true
44 fi
45 done
46
47 if [[ "$found_keys" == "false" ]]; then
48 echo "No SSH keys found."
49 echo "Generate keys with: tin key generate <nas-server>"
50 fi
51}
52
53# Main execution
54list_nas_keys