diff options
author | Erich Eckner <git@eckner.net> | 2022-05-23 21:27:59 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2022-05-23 21:27:59 +0200 |
commit | 4e6e1f744c7838d95b6a94f1fff1a3d613adf498 (patch) | |
tree | c9ff6a81f74c8ac980969f22890f8b6f639afcae | |
parent | e5f128f14d49dbd44a078b0d298a9cf768bc8101 (diff) | |
download | ssh-keystore-4e6e1f744c7838d95b6a94f1fff1a3d613adf498.tar.xz |
scripts/check-keys: make runnable for other users
-rwxr-xr-x | scripts/check-keys | 14 |
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" |