Friday, June 15, 2018

SSH Agent to key forwarding

SSH를 이용해 일를 하다보면 여러 컴퓨터를 지나서 최종 목적지에 도착하는 경우가 왕왕 있다. 이때 SSH Agent to key forwarding이 필요하다. 특히 보안을 중요시하는 시스템에서는 아예 비밀번호를 쓰지 못하고 등록된 키만 이용해야 하는 경우도 있다.

% ssh-agent > agent.sh
% source agent.sh
% ssh-add ~/.ssh/id_rsa
% .bash_profile

GREP=grep
test=`/bin/ps -ef | $GREP ssh-agent | $GREP -v grep | /usr/bin/awk '{print $2}' | xargs`

if [ "$test" = "" ]; then
   # there is no agent running
   if [ -e "$HOME/agent.sh" ]; then
      # remove the old file
      rm -f $HOME/agent.sh
   fi;
   # start a new agent
   ssh-agent | $GREP -v echo >&$HOME/agent.sh
   ssh-add ~/.ssh/id_rsa
fi;

test -e $HOME/agent.sh && source $HOME/agent.sh

alias kagent="kill -9 $SSH_AGENT_PID"


Reference: https://drupal.star.bnl.gov/STAR/blog-entry/jeromel/2009/feb/02/ssh-quick-instructions-users-without-password

No comments:

Post a Comment