From 42f1b3b74b1dd64cd2c23e7100a57a44c54b00a9 Mon Sep 17 00:00:00 2001 From: Russ Long Date: Thu, 7 Feb 2019 13:43:22 -0500 Subject: [PATCH] Initial Commit --- ssh.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 ssh.sh diff --git a/ssh.sh b/ssh.sh new file mode 100755 index 0000000..85ac9b4 --- /dev/null +++ b/ssh.sh @@ -0,0 +1,40 @@ +#!/bin/bash +#Maintained by Linux Operations - Russ Long - + +#Set variables +keyname=${1} + +hostname=${2} + +keyfile=$HOME/.ssh/${keyname}_$(date "+%F-%T") +#Check to see if user is logged in to lastpass cli +#check_login() +#{ + if lpass status | grep -q "Logged in as"; then + echo "Logged in to Lastpass, continuing..." + else + echo "Please login with 'lpass login email@address.com'" + exit 1 + fi +#} + +#Fetch private key and place in /home/$user/.ssh/$hostname.datetime +lpass show $keyname --field="Private Key" > $keyfile +chmod 0600 $keyfile + +#store passphrase in a variable +sshpassphrase=$(lpass show $keyname --field=Passphrase) + +#Add the key to ssh-agent +expect << EOF + spawn ssh-add $keyfile + expect "Enter passphrase" + send "$sshpassphrase\r" + expect eof +EOF + +#SSH to the host +ssh $hostname + +#remove the key +rm -f $keyfile