summaryrefslogtreecommitdiff
path: root/examples/update_key_cache.sh.example
diff options
context:
space:
mode:
authorPaul Buetow <35781042+pbuetow@users.noreply.github.com>2023-06-22 21:27:14 +0300
committerGitHub <noreply@github.com>2023-06-22 21:27:14 +0300
commit14654b432c0a5494001af330c9d4cb7efaa535bf (patch)
treee782b38060766ac89d9dd24da143b9088a3f6909 /examples/update_key_cache.sh.example
parent294a4239831c2b2bda5933dde8a2ededf7eb476e (diff)
parent16b2ea0f93ebe8fbb8f3dea05d3fa60456513938 (diff)
Merge pull request #33 from snonux/master
Release v4.2.0
Diffstat (limited to 'examples/update_key_cache.sh.example')
-rw-r--r--examples/update_key_cache.sh.example33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/update_key_cache.sh.example b/examples/update_key_cache.sh.example
new file mode 100644
index 0000000..9817f04
--- /dev/null
+++ b/examples/update_key_cache.sh.example
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+declare -r CACHEDIR=/var/run/dserver/cache
+declare -r DSERVER_USER=dserver
+
+echo "Updating SSH key cache"
+
+ls /home/ | while read remoteuser; do
+ keysfile=/home/$remoteuser/.ssh/authorized_keys
+
+ if [ -f $keysfile ]; then
+ cachefile=$CACHEDIR/$remoteuser.authorized_keys
+ echo "Caching $keysfile -> $cachefile"
+
+ cp $keysfile $cachefile
+ chown $DSERVER_USER $cachefile
+ chmod 600 $cachefile
+ fi
+done
+
+# Cleanup obsolete public SSH keys
+find $CACHEDIR -name \*.authorized_keys -type f |
+while read cachefile; do
+ remoteuser=$(basename $cachefile | cut -d. -f1)
+ keysfile=/home/$remoteuser/.ssh/authorized_keys
+
+ if [ ! -f $keysfile ]; then
+ echo "Deleting obsolete cache file $cachefile"
+ rm $cachefile
+ fi
+done
+
+echo "All set..."