summaryrefslogtreecommitdiff
path: root/samples/update_key_cache.sh.sample
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-01-09 20:30:15 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-01-09 20:30:15 +0000
commit3755a9911ecb05886577095f2b8cc8b9e4066a3a (patch)
tree86e24bc466986cb5c9c6d167a918e6064defeafc /samples/update_key_cache.sh.sample
Release of DTail v1.0.0v1.0.0
Diffstat (limited to 'samples/update_key_cache.sh.sample')
-rw-r--r--samples/update_key_cache.sh.sample33
1 files changed, 33 insertions, 0 deletions
diff --git a/samples/update_key_cache.sh.sample b/samples/update_key_cache.sh.sample
new file mode 100644
index 0000000..9817f04
--- /dev/null
+++ b/samples/update_key_cache.sh.sample
@@ -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..."