summaryrefslogtreecommitdiff
path: root/examples/update_key_cache.sh.example
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2023-06-21 10:56:41 +0000
committerPaul Buetow <pbuetow@mimecast.com>2023-06-21 10:56:41 +0000
commitc5fd63e099cec30154e2a9c0b5ee7715491263bf (patch)
tree691e46f0930804e6a8ad0a234f293db917859f5a /examples/update_key_cache.sh.example
parentdaaca90c2c1c9debc339ff28c3f0b928b5041d3e (diff)
DTail: Restrict SSH MAC algorithms allowed - Update of few dependencies
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..."