[CentOS] scp and key login

Wed Oct 1 18:07:36 UTC 2008
Phil Schaffner <Philip.R.Schaffner at NASA.gov>

On Wed, 2008-10-01 at 11:37 -0400, Tony Schreiner wrote:
...
> As far as I know that's right. Though it can be scripted into your  
> login.

Been doing it so long I can't remember whom to credit, but I use the
following snippet added to the end of ~/.bash_profile:

#*************************************************************#
AGENTFILE=$HOME/.ssh/current-ssh-agent
test -f $AGENTFILE && . $AGENTFILE
if test -n "$SSH_AGENT_PID" \
  && ps xo pid,comm | grep -q "$SSH_AGENT_PID ssh-agent$"; then
  if ssh-add -l >/dev/null; then
    # Everything seems OK.
    :
  else
    # Agent is running but knows no identities.
    echo SSH-AGENT:  No identities.  Remember to run ssh-add!
  fi
else
  # No agent is running or AGENTFILE is lost - start a new one.
  if ps xo comm | grep -q "^ssh-agent$"; then
    echo SSH-AGENT:  Stray ssh-agent\?  Killing it.
    killall -TERM ssh-agent
  fi
  echo SSH-AGENT:  A new agent started.  Remember to run ssh-add!
  ssh-agent | grep -v '^echo' >$AGENTFILE
fi
. $AGENTFILE
unset AGENTFILE
#*************************************************************#

and this to ~/.bash_logout:

#*************************************************************#
if test $(w -hsf $(id -un) | wc -l) = 1; then ssh-add -D fi
#*************************************************************#

For KDE one can use a script "ssh-add.sh" containing the following in
~/.kde/Autostart to prompt for the passphrase:

#!/bin/bash
sleep 5
konsole --vt_sz 60x4--noframe  --nomenubar --notoolbar --noscrollbar  -e ssh-add

Watch for line-wraps on the above, and remember to
$ chmod +x ~/.kde/Autostart/ssh-add.sh

Phil