summaryrefslogtreecommitdiff
path: root/scripts/check-keys
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/check-keys')
-rwxr-xr-xscripts/check-keys14
1 files changed, 12 insertions, 2 deletions
diff --git a/scripts/check-keys b/scripts/check-keys
index ecdbfe6..6a417fe 100755
--- a/scripts/check-keys
+++ b/scripts/check-keys
@@ -2,16 +2,26 @@
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=$(whoami)
+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
-diff -u --color "hosts/${host}/${user}" ~/.ssh/authorized_keys
+home_dir=$(
+ getent passwd "${user}" \
+ | cut -d: -f6
+)
+
+diff -u --color "hosts/${host}/${user}" "${home_dir}/.ssh/authorized_keys"