summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-05-23 21:46:31 +0200
committerErich Eckner <git@eckner.net>2022-05-23 21:46:31 +0200
commit44002f3a4e371d6a6831fe08d7884b0d3badf536 (patch)
tree9780efcb608059f6913343a998fd21d52a0eed5c
parent4e6e1f744c7838d95b6a94f1fff1a3d613adf498 (diff)
downloadssh-keystore-44002f3a4e371d6a6831fe08d7884b0d3badf536.tar.xz
scripts/check-keys: make possible to check all keys
-rwxr-xr-xscripts/check-keys16
1 files changed, 11 insertions, 5 deletions
diff --git a/scripts/check-keys b/scripts/check-keys
index 6a417fe..360a2c6 100755
--- a/scripts/check-keys
+++ b/scripts/check-keys
@@ -1,5 +1,12 @@
#!/bin/bash
+if [ $# -eq 0 ] && [ $(whoami) = 'root' ]; then
+ getent passwd \
+ | cut -d: -f1 \
+ | parallel "${0}"
+ exit $?
+fi
+
cd "${0%/*}/.."
if [ $# -gt 1 ]; then
@@ -14,14 +21,13 @@ if [ ! -d "hosts/${host}" ]; then
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
)
+if [ ! -f "hosts/${host}/${user}" ] && [ ! -f "${home_dir}/.ssh/authorized_keys" ]; then
+ exit 0
+fi
+
diff -u --color "hosts/${host}/${user}" "${home_dir}/.ssh/authorized_keys"