Browse Source

Added plugin to run hooks on SSH login

R. Alex Matevish 6 years ago
parent
commit
df068b259d
1 changed files with 28 additions and 0 deletions
  1. 28 0
      ssh_hook.sh

+ 28 - 0
ssh_hook.sh

@@ -0,0 +1,28 @@
+#############################################################################
+#
+# SSH Login Hooks
+#
+#############################################################################
+
+function _setup_ssh_hook_env () {
+    # Run to set the SESSION_TYPE
+    if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
+        SESSION_TYPE=remote/ssh  # Add more tests 
+    else
+        case $(ps -o comm= -p $PPID) in sshd|*/sshd)
+            SESSION_TYPE=remote/ssh;;
+        esac
+    fi
+}
+
+_setup_ssh_hook_env;
+if file_exists ~/.ssh_hooks; then
+    source ~/.ssh_hooks
+fi
+
+if is_function ssh_login_hook; then
+    if [ $SESSION_TYPE = 'remote/ssh' ]; then
+        ssh_login_hook
+    fi
+fi
+