summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-05-23 21:27:59 +0200
committerErich Eckner <git@eckner.net>2022-05-23 21:27:59 +0200
commit4e6e1f744c7838d95b6a94f1fff1a3d613adf498 (patch)
treec9ff6a81f74c8ac980969f22890f8b6f639afcae
parente5f128f14d49dbd44a078b0d298a9cf768bc8101 (diff)
downloadssh-keystore-4e6e1f744c7838d95b6a94f1fff1a3d613adf498.tar.xz
scripts/check-keys: make runnable for other users
-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"