summaryrefslogtreecommitdiff
path: root/scripts/check-keys
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/check-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"