Add username spec

This commit is contained in:
Russ Long 2019-03-19 09:01:05 -04:00
parent 97ca243214
commit 0d7158795e
3 changed files with 9 additions and 6 deletions

View File

@ -9,7 +9,7 @@ The SSH Key must be stored in your lastpass account, as a Secure Note of the typ
## Usage ## Usage
1. Download the script to a location of your choosing, ensuring it is executable 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 ## 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. 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 ## Usage
1. Download the script to a location of your choosing, ensuring it is executable 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. 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 ## How it works

View File

@ -3,7 +3,8 @@
#Set variables #Set variables
keyname=${1} keyname=${1}
hostname=${2} username=${2}
hostname=${3}
keyfile=$HOME/.ssh/${keyname}-$(date "+%s") keyfile=$HOME/.ssh/${keyname}-$(date "+%s")
pubkeyfile=$HOME/.ssh/${keyname}-$(date "+%s").pub pubkeyfile=$HOME/.ssh/${keyname}-$(date "+%s").pub
@ -42,7 +43,7 @@ fi
#Add the key to ssh-agent #Add the key to ssh-agent
echo "Copying id to $hostname, you may be asked to authenticate to SSH." 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 #Remove keyfiles
rm -f $keyfile rm -f $keyfile

6
ssh.sh
View File

@ -4,7 +4,9 @@
#Set variables #Set variables
keyname=${1} keyname=${1}
hostname=${2} username=${2}
hostname=${3}
keyfile=$HOME/.ssh/${keyname}-$(date "+%s") 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
@ -34,7 +36,7 @@ expect << EOF
EOF EOF
#SSH to the host #SSH to the host
ssh $hostname ssh $username@$hostname
#Remove keyfile #Remove keyfile
rm -f $keyfile rm -f $keyfile