From 44002f3a4e371d6a6831fe08d7884b0d3badf536 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 23 May 2022 21:46:31 +0200 Subject: scripts/check-keys: make possible to check all keys --- scripts/check-keys | 16 +++++++++++----- 1 file 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" -- cgit v1.2.3-54-g00ecf