#!/bin/sh # ssh-agent-kill - kill ssh-agent processes, FIFOs, and cached process info # Andrew Ho (andrew@zeuscat.com) # # Usage: eval `ssh-agent-kill` # Also see ssh-agent-persist. # # See http://www.zeuscat.com/andrew/software/desktop_hacks/#ssh-agent-persist # for some background information about how I use this script. ME=`basename "$0"` if [ "x$USER" = "x" ]; then USER="$USERNAME" if [ "x$USER" = "x" ]; then USER="$LOGNAME" if [ "x$USER" = "x" ]; then echo "echo '$ME: could not determine username' 2>&1" exit 1 fi fi fi if [ "x$HOME" = "x" ]; then echo "echo '$ME: could not determine home directory' 2>&1" exit 1 fi SSH_AGENT_ROOT="$HOME/.ssh-agent" ssh_agent_pids=`ps -ef \ | grep "$USER" | grep ssh-agent | grep -v grep | grep -v "$ME" \ | awk '{ print $2 }'` if [ "x$ssh_agent_pids" != "x" ]; then echo "echo 'Killing ssh-agent pids: $ssh_agent_pids';" kill -9 $ssh_agent_pids fi if [ -d "/tmp/ssh-$USER" ]; then echo "echo 'Removing ssh-agent FIFOs in /tmp/ssh-$USER';" rm -rf "/tmp/ssh-$USER" fi HOSTNAME=`hostname` if [ "x$HOSTNAME" = "x" ]; then echo "echo '$ME: could not determine hostname' 2>&1;" HOSTNAME=unknown else case "$HOSTNAME" in *.tellme.com) ;; *) HOSTNAME="$HOSTNAME.tellme.com" ;; esac fi filename="$SSH_AGENT_ROOT/$HOSTNAME" if [ -f "$filename" ]; then echo "echo 'Removing ssh-agent state: $filename';" rm "$filename" fi if [ "x$SSH_AUTH_SOCK" != "x" ]; then echo "unset SSH_AUTH_SOCK;" fi if [ "x$SSH_AGENT_PID" != "x" ]; then echo "unset SSH_AGENT_PID;" fi exit 0