summaryrefslogtreecommitdiff
path: root/scripts/check-keys
blob: 6a417fedc28093ad37bcb187a1c95f3090666b91 (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
26
27
#!/bin/bash

cd "${0%/*}/.."

if [ $# -gt 1 ]; then
  >&2 echo 'usage: '"$0"' [user]'
  exit 1
fi

host=$(uname -n)
if [ ! -d "hosts/${host}" ]; then
  >&2 printf 'no keys for host %s\n' "${host}"
  exit 1
fi

user="${1:-$(whoami)}"
if [ ! -f "hosts/${host}/${user}" ]; then
  >&2 printf 'no keys for user %s on host %s\n' "${user}" "${host}"
  exit 1
fi

home_dir=$(
  getent passwd "${user}" \
  | cut -d: -f6
)

diff -u --color "hosts/${host}/${user}" "${home_dir}/.ssh/authorized_keys"