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