Add key expiration to ssh-add

This commit is contained in:
Russ Long 2019-02-07 14:06:12 -05:00
parent a29c8b5d67
commit 44c8da3f88

9
ssh.sh
View File

@ -6,7 +6,7 @@ keyname=${1}
hostname=${2} hostname=${2}
keyfile=$HOME/.ssh/${keyname}_$(date "+%F-%T") keyfile=$HOME/.ssh/${keyname}-$(date "+%s")
#Check to see if user is logged in to lastpass cli #Check to see if user is logged in to lastpass cli
#check_login() #check_login()
#{ #{
@ -27,7 +27,7 @@ sshpassphrase=$(lpass show $keyname --field=Passphrase)
#Add the key to ssh-agent #Add the key to ssh-agent
expect << EOF expect << EOF
spawn ssh-add $keyfile spawn ssh-add -t 30 $keyfile
expect "Enter passphrase" expect "Enter passphrase"
send "$sshpassphrase\r" send "$sshpassphrase\r"
expect eof expect eof
@ -36,8 +36,5 @@ EOF
#SSH to the host #SSH to the host
ssh $hostname ssh $hostname
#remove the key from the ssh-agent #Remove keyfile
ssh-add -d $keyfile
#remove the key
rm -f $keyfile rm -f $keyfile