From 2f2e38c14302da96eaaee10b4492c928722548c8 Mon Sep 17 00:00:00 2001 From: Russ Long Date: Tue, 19 Mar 2019 11:06:07 -0400 Subject: [PATCH] Allow for spacing --- ssh-copy-id.sh | 15 ++++++++------- ssh.sh | 12 +++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ssh-copy-id.sh b/ssh-copy-id.sh index 93d5f7a..5e2fc74 100755 --- a/ssh-copy-id.sh +++ b/ssh-copy-id.sh @@ -2,11 +2,12 @@ #Maintained by Linux Operations - Russ Long - #Set variables -keyname=${1} +keyname="${1}" username=${2} hostname=${3} -keyfile=$HOME/.ssh/${keyname}-$(date "+%s") -pubkeyfile=$HOME/.ssh/${keyname}-$(date "+%s").pub +keysavename=$(echo -e ${keyname} | tr -d '[:space:]' | awk -F"/" '{print $NF}') +keyfile=$HOME/.ssh/${keysavename}-$(date "+%s") +pubkeyfile=$HOME/.ssh/${keysavename}-$(date "+%s").pub #Check to see if user is logged in to lastpass cli if lpass status | grep -q "Logged in as"; then @@ -16,12 +17,12 @@ else exit 1 fi -#Fetch private key and place in /home/$user/.ssh/$keyname-datetime -lpass show $keyname --field="Private Key" > $keyfile +#Fetch private key and place in /home/$user/.ssh/$keysavename-datetime +lpass show "$keyname" --field="Private Key" > $keyfile chmod 0600 $keyfile -#Fetch public Key and place in /home/$user/.ssh/$keyname-datetime.pub -lpass show $keyname --field="Public Key" > $pubkeyfile +#Fetch public Key and place in /home/$user/.ssh/$keysavename-datetime.pub +lpass show "$keyname" --field="Public Key" > $pubkeyfile #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 diff --git a/ssh.sh b/ssh.sh index 9681bc2..d5625d7 100755 --- a/ssh.sh +++ b/ssh.sh @@ -2,13 +2,15 @@ #Maintained by Linux Operations - Russ Long - #Set variables -keyname=${1} +keyname="${1}" username=${2} 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_login() #{ @@ -20,12 +22,12 @@ keyfile=$HOME/.ssh/${keyname}-$(date "+%s") fi #} -#Fetch private key and place in /home/$user/.ssh/$keyname_datetime -lpass show $keyname --field="Private Key" > $keyfile +#Fetch private key and place in /home/$user/.ssh/$keysavename_datetime +lpass show "$keyname" --field="Private Key" > $keyfile chmod 0600 $keyfile #store passphrase in a variable -sshpassphrase=$(lpass show $keyname --field=Passphrase) +sshpassphrase=$(lpass show "$keyname" --field=Passphrase) #Add the key to ssh-agent expect << EOF