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
commitc1aa5b1e52734e2498af1e8e616e1f8842b5f7f0 (patch)
tree691e46f0930804e6a8ad0a234f293db917859f5a /examples/update_key_cache.sh.example
parent2961390ac9fbe9657b5df231e005db34133834fe (diff)
parent552702e5f7cd36824a5982419488f960611a9a80 (diff)
Merge branch 'develop' into 'master'
DTail: Restrict SSH MAC algorithms allowed - Update of few dependencies See merge request Storage/dtail!7
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..."