Logging into many a remote hosts and, or servers from my desktop and, or notebook is a routine job for me, hence I extensively use ssh and ssh-agent every day. I wanted to use the same ssh-agent instance from each and every terminal whether I’m on a virtual console or in front of x-window desktop running a terminal emulator. I created a tiny bash script say ssh-agent.sh in the /etc/profile.d as follows:
SSH_ENV="$HOME/.ssh/ssh-agent.env"
function start_agent {
/usr/bin/ssh-agent |sed 's/^echo/#echo/' >"$SSH_ENV"
chmod 600 "$SSH_ENV"
. "$SSH_ENV" >/dev/null
}
# Source SSH settings, if applicable
if [ -f "$SSH_ENV" ]; then
. "$SSH_ENV" >/dev/null
ps -e |grep ^$SSH_AGENT_PID |grep -q ssh-agent$ || start_agent
else
start_agent
fi
And the life now seems quite easier since then