Allow for spacing

This commit is contained in:
Russ Long 2019-03-19 11:06:07 -04:00
parent 0d7158795e
commit 2f2e38c143
2 changed files with 15 additions and 12 deletions

View File

@ -2,11 +2,12 @@
#Maintained by Linux Operations - Russ Long - <rlong@nabancard.com> #Maintained by Linux Operations - Russ Long - <rlong@nabancard.com>
#Set variables #Set variables
keyname=${1} keyname="${1}"
username=${2} username=${2}
hostname=${3} hostname=${3}
keyfile=$HOME/.ssh/${keyname}-$(date "+%s") keysavename=$(echo -e ${keyname} | tr -d '[:space:]' | awk -F"/" '{print $NF}')
pubkeyfile=$HOME/.ssh/${keyname}-$(date "+%s").pub keyfile=$HOME/.ssh/${keysavename}-$(date "+%s")
pubkeyfile=$HOME/.ssh/${keysavename}-$(date "+%s").pub
#Check to see if user is logged in to lastpass cli #Check to see if user is logged in to lastpass cli
if lpass status | grep -q "Logged in as"; then if lpass status | grep -q "Logged in as"; then
@ -16,12 +17,12 @@ else
exit 1 exit 1
fi fi
#Fetch private key and place in /home/$user/.ssh/$keyname-datetime #Fetch private key and place in /home/$user/.ssh/$keysavename-datetime
lpass show $keyname --field="Private Key" > $keyfile lpass show "$keyname" --field="Private Key" > $keyfile
chmod 0600 $keyfile chmod 0600 $keyfile
#Fetch public Key and place in /home/$user/.ssh/$keyname-datetime.pub #Fetch public Key and place in /home/$user/.ssh/$keysavename-datetime.pub
lpass show $keyname --field="Public Key" > $pubkeyfile lpass show "$keyname" --field="Public Key" > $pubkeyfile
#Ask user if they wish to remove old keys #Ask user if they wish to remove old keys
read -r -p "Do you wish to remove ALL other ssh keys for your user on $hostname? [Y/n]" removeresponse read -r -p "Do you wish to remove ALL other ssh keys for your user on $hostname? [Y/n]" removeresponse

12
ssh.sh
View File

@ -2,13 +2,15 @@
#Maintained by Linux Operations - Russ Long - <rlong@nabancard.com> #Maintained by Linux Operations - Russ Long - <rlong@nabancard.com>
#Set variables #Set variables
keyname=${1} keyname="${1}"
username=${2} username=${2}
hostname=${3} hostname=${3}
keyfile=$HOME/.ssh/${keyname}-$(date "+%s") keysavename=$(echo -e ${keyname} | tr -d '[:space:]' | awk -F"/" '{print $NF}')
keyfile=$HOME/.ssh/${keysavename}-$(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()
#{ #{
@ -20,12 +22,12 @@ keyfile=$HOME/.ssh/${keyname}-$(date "+%s")
fi fi
#} #}
#Fetch private key and place in /home/$user/.ssh/$keyname_datetime #Fetch private key and place in /home/$user/.ssh/$keysavename_datetime
lpass show $keyname --field="Private Key" > $keyfile lpass show "$keyname" --field="Private Key" > $keyfile
chmod 0600 $keyfile chmod 0600 $keyfile
#store passphrase in a variable #store passphrase in a variable
sshpassphrase=$(lpass show $keyname --field=Passphrase) sshpassphrase=$(lpass show "$keyname" --field=Passphrase)
#Add the key to ssh-agent #Add the key to ssh-agent
expect << EOF expect << EOF