#!/bin/bash # Launch the ssh-agent from a service so it survives logoff. # When the service stops, kill the ssh-agent. trap "ssh-agent -k; exit 0" TERM # Clean up old files that may be left behind after a crash. # The file permissions make this safe to do in a multi-user # environment, but "/tmp" must be local to this host. rm -rf /tmp/ssh-* # Launch the ssh-agent. eval $(ssh-agent) # Provide the ssh-agent socket ID via the registry and broadcast # the change in case the user is logged before we finish. # Do not provide the ssh-agent PID to minimize the risk of # killing the ssh-agent. regtool -s set /HKEY_CURRENT_USER/Environment/SSH_AUTH_SOCK $SSH_AUTH_SOCK sendchenv # Wait quietly until the service is stopped. while true; do sleep 24h & wait done