Issue
When I write .bashrc script to hold pubkey passphrase, the most important command is:
eval `ssh-agent -s`
The problem is, if the session exits, ssh-agent will be closed automatically which leads to the need of entering passphrase again in the next session. What I want is to set passphrase only once until the system reboot. Therefore I try:
eval `nohup ssh-agent -s`
Hope ssh-agent can live out of starting session like other long run processes. However, it does NOT work... Why? And how to achieve my goal?
Thank you in advance.
FYI, the whole script is:
ssh-reagent() {
for agent in $TMPDIR/ssh-*/agent.*; do
export SSH_AUTH_SOCK=$agent
if ssh-add -l &> /dev/null; then
echo "Found working SSH Agent:"
ssh-add -l
return
else
rm -rf $(dirname ${SSH_AUTH_SOCK})
export SSH_AUTH_SOCK=
fi
done
eval `ssh-agent -s` # <-- How to keep ssh-agent alive when logout?
ssh-add ~/.ssh/id_rsa
}
ssh-reagent
Solution
No! Wrong approach! Instead you just have to take care where you start the ssh-agent. You should not do it for each and every shell you start, but only once for the login shell. That one spawns all other processes of a user, so the agent will be available in all until the user logs out again.
Typical places are:
/etc/X11/xdm/sys.xsession
or~/.xsession
for a graphical login/etc/profile
,~/.profile
or~/.bash_profile
for a normal login shell
This depends a bit on your distribution and your personal preferences.
Answered By - arkascha