diff --git a/README.md b/README.md index b9e6698..919ba2d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The SSH Key must be stored in your lastpass account, as a Secure Note of the typ ## Usage 1. Download the script to a location of your choosing, ensuring it is executable -2. run it like this: ```./ssh.sh KEYNAME server-you-wish-to-ssh-to``` +2. run it like this: ```./ssh.sh KEYNAME USERNAME server-you-wish-to-ssh-to``` ## How it works This script uses the official `lastpass-cli` package to pull the private key to a file and the private key passphrase to a variable. The script then uses that information to ssh to the requested server, and removes the private key when the connection is closed. @@ -22,7 +22,7 @@ The SSH Key must be stored in your lastpass account, as a Secure Note of the typ ## Usage 1. Download the script to a location of your choosing, ensuring it is executable -2. run it like this: ```./ssh-copy-id.sh KEYNAME server-you-wish-to-ssh-to``` +2. run it like this: ```./ssh-copy-id.sh KEYNAME USERNAME server-you-wish-to-ssh-to``` 3. You will be prompted to answer if you would like to remove all old ssh keys currently installed on the remote host. This is strongly recommended. ## How it works diff --git a/ssh-copy-id.sh b/ssh-copy-id.sh index 6b181fd..93d5f7a 100755 --- a/ssh-copy-id.sh +++ b/ssh-copy-id.sh @@ -3,7 +3,8 @@ #Set variables keyname=${1} -hostname=${2} +username=${2} +hostname=${3} keyfile=$HOME/.ssh/${keyname}-$(date "+%s") pubkeyfile=$HOME/.ssh/${keyname}-$(date "+%s").pub @@ -42,7 +43,7 @@ fi #Add the key to ssh-agent echo "Copying id to $hostname, you may be asked to authenticate to SSH." -ssh-copy-id -i $pubkeyfile $hostname +ssh-copy-id -i $pubkeyfile $username@$hostname #Remove keyfiles rm -f $keyfile diff --git a/ssh.sh b/ssh.sh index 8d9ef96..9681bc2 100755 --- a/ssh.sh +++ b/ssh.sh @@ -4,7 +4,9 @@ #Set variables keyname=${1} -hostname=${2} +username=${2} + +hostname=${3} keyfile=$HOME/.ssh/${keyname}-$(date "+%s") #Check to see if user is logged in to lastpass cli @@ -34,7 +36,7 @@ expect << EOF EOF #SSH to the host -ssh $hostname +ssh $username@$hostname #Remove keyfile rm -f $keyfile