#!/bin/bash # Launch the ssh-agent from a service so it survives logoff. # Where are we? host=$(uname -n) # When the service stops, kill the ssh-agent. trap "rm -f ~/.keychain/${host}-svc; rm -f ~/.keychain/${host}.bat; keychain --quiet --stop; exit 0" TERM # Launch the ssh-agent. keychain --quiet # If keychain was successful then... if [ -e ~/.keychain/${host}-sh ]; then # Create a ".bat" file for use in Windows command shells. : > ~/.keychain/${host}.bat && \ chmod 0600 ~/.keychain/${host}.bat && \ cat ~/.keychain/${host}-sh | sed -e 's/;.*//' -e 's/^/@set /' >> ~/.keychain/${host}.bat # Show the service as available. : > ~/.keychain/${host}-svc && \ chmod 0600 ~/.keychain/${host}-svc && \ echo $$ >> ~/.keychain/${host}-svc fi # Wait quietly until the service is stopped. while true; do sleep 24h & wait done