Last active
January 4, 2019 18:53
-
-
Save lttlrck/95d3952ebf25e36e4356d60118c6a706 to your computer and use it in GitHub Desktop.
quick SSH using peco, remembers past connections, presents a filterable list. relies on SSH keys for auth.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sss() { | |
cat ~/.connections | sort | uniq > ~/.connections_ && mv ~/.connections_ ~/.connections | |
IFS=$'\n' array=($(cat ~/.connections | cut -d" " -f1 | peco --print-query)) | |
r1=${array[1]} | |
r2=${array[2]} | |
addr="" | |
if [[ "$r2" == "" ]]; then | |
#echo No match, using $r1 | |
addr=$r1 | |
else | |
# echo match, using $r2 | |
addr=$r2 | |
fi | |
user=$(cat ~/.connections | grep $addr | cut -d" " -f2) | |
if [[ "$user" == "" ]]; then | |
echo Enter user | |
read user | |
fi | |
ssh -o PreferredAuthentications=publickey $user@$addr | |
if [[ $? == 0 ]]; then | |
echo $addr $user >> ~/.connections | |
else | |
echo Failed, try installing public key | |
ssh-copy-id $user@$addr | |
ssh -o PreferredAuthentications=publickey $user@$addr | |
if [[ $? == 0 ]]; then | |
echo $addr $user >> ~/.connections | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment