Jay Taylor's notes

back to listing index

SSH agent forwarding and screen

[web search]
Original source (gist.github.com)
Tags: screen ssh-agent-forwarding gist.github.com
Clipped on: 2017-06-19

Image (Asset 1/14) alt= btw: both boxen are FreeBSD. The FBSD core committers change some of the ssh defaults to enhance security which might explain the differences if Linux exhibits differently?

Image (Asset 2/14) alt= I use following in my .bashrc

export SSH_AUTH_SOCK=$(find /tmp -maxdepth 2 -type s -name "agent*" -user $USER -printf '%T@ %p\n' 2>/dev/null |sort -n|tail -1|cut -d' ' -f2)

And then i just reread my .bashrc in screen windows to apply working ssh socket.

Image (Asset 3/14) alt= start screen
ssh to computer 2 (confirm can ssh to computer 3 via forwarding; exit back to computer 2)
detach
log off computer 1
ssh to computer 1
re-attach screen

expect to be on computer 2

ssh to computer 3 (fails)

Will this method fair better?

Image (Asset 4/14) alt= found here: https://gist.github.com/duijf/baeeec8197cdf81448370cf33dc0e708

function start_agent {
  echo "Initialising new SSH agent..."
  /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  echo Succeeded
  chmod 600 "${SSH_ENV}"
  . "${SSH_ENV}" > /dev/null
  /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
  . "${SSH_ENV}" > /dev/null
  ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
    start_agent;
  }
else
  start_agent
fi

atm idk how to pair this with tmux, someone?

Or adopt this awesomeness: https://github.com/wwalker/ssh-find-agent

Image (Asset 5/14) alt=