Browse code

Add steal-ssh-agent.

Xavier G authored on29/07/2016 07:11:42
Showing1 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+#!/bin/bash
2
+# "Steal" the ssh-agent, assuming there is only one running and we
3
+# are actually allowed to reach its socket (i.e. we are either root
4
+# or the ssh-agent owner).
5
+ssh_agent_pid=$(pgrep -f "^/usr/bin/ssh-agent")
6
+if [ -z "${ssh_agent_pid}" ]; then
7
+	echo "Unable to find ssh-agent"
8
+	exit 158
9
+fi
10
+ssh_agent_ppid=$(perl -nlE 'say $1 if m#^PPid:\s*(\d+)$#' /proc/${ssh_agent_pid}/status)
11
+export SSH_AGENT_PID="${ssh_agent_pid}"
12
+export SSH_AUTH_SOCK=$(/bin/ls /tmp/ssh-*/agent.${ssh_agent_ppid})
13
+[ $# -gt 0 ] && "$@"