ssh-agent免登陆shell脚本

引用
新建ssh-attach.sh脚本

#!/bin/bash
un=`id | awk '{print substr($0,index($0,"(")+1, index($0,")")-index($0,"(")-1)}'`
sas=0
for i in `find /tmp -user ${un} -type s 2>/dev/null`
do
  sas=$i
  SSH_AUTH_SOCK=$i
done
if [ $sas != 0 ]
then
  export SSH_AUTH_SOCK=$sas
  export SSH_AGENT_PID=`echo $SSH_AUTH_SOCK | awk -F'.' '{print $NF+1}'`
else
  ssh-agent 
  ssh-add
fi  



引用
vi .bashrc文件,最后一行加入

eval ~/ssh-attach.sh

猜你喜欢

转载自asflex.iteye.com/blog/2065886