Last active
January 3, 2019 20:10
-
-
Save lttlrck/791551452e0b1e6eec047f7ba91923e6 to your computer and use it in GitHub Desktop.
Use peco, jq and bitwarden for SSH login
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
# gets user name and password from bitwarden | |
# keeps a list of all conenctions, and presents them in peco so easy filtering | |
export BW_SESSION="***************************" | |
sss() { | |
cat .connections | sort | uniq > .connections_ && mv .connections_ .connections | |
IFS=$'\n' array=($(cat .connections | 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 | |
o=$(bw list items --search $addr) | |
u=$(echo $o | jq -r ".[0].login.username") | |
p=$(echo $o | jq -r ".[0].login.password") | |
echo login as $u | |
sshpass -p $p ssh $u@$addr | |
if [[ $? == 0 ]]; then | |
echo $addr >> .connections | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment