From 837f260151848c2acd6df1d52f6cc6d8fc1611aa Mon Sep 17 00:00:00 2001 From: Mikhail Golbakh Date: Mon, 25 Jul 2022 00:04:19 +0300 Subject: [PATCH] fix: improve authentication method check --- sshp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sshp b/sshp index e9f3876..662bbf0 100755 --- a/sshp +++ b/sshp @@ -1,6 +1,7 @@ #!/usr/bin/env bash OPENSSL_ENC_FLAGS=("-des3" "-base64" "-pbkdf2") +SSH_META_DIR="$HOME/.ssh/meta" show_help() { cat <&2 @@ -69,7 +70,7 @@ remove_creds() { creds_name="$1" - meta_filepath="$HOME/.ssh/meta/$creds_name" + meta_filepath="$SSH_META_DIR/$creds_name" if [[ ! -f "$meta_filepath" ]]; then echo "Credentials $creds_name is not exist" >&2 @@ -81,7 +82,7 @@ remove_creds() { } list_creds() { - for meta_filepath in $HOME/.ssh/meta/*; do + for meta_filepath in $SSH_META_DIR/*; do [[ -f "$meta_filepath" ]] || continue creds_name=$(basename "$meta_filepath") @@ -94,7 +95,7 @@ list_creds() { get_pass() { creds_name="$1" - meta_filepath="$HOME/.ssh/meta/$creds_name" + meta_filepath="$SSH_META_DIR/$creds_name" if [[ ! -f "$meta_filepath" ]]; then echo "Credentials $creds_name is not exist" >&2 @@ -131,7 +132,7 @@ connect() { creds_name="$1" - meta_filepath="$HOME/.ssh/meta/$creds_name" + meta_filepath="$SSH_META_DIR/$creds_name" if [[ -z "$creds_name" || ! -f "$meta_filepath" ]]; then ssh "$@" @@ -173,8 +174,8 @@ connect() { echo -n "$pass" | xclip -selection clipboard fi - # If ident file is provided connect without sshpass to catch key passphrase if needed - if [[ -n "$ident_filepath" ]]; then + # Check if authentication should be via pubkey + if ssh -v -o BatchMode=yes "${ssh_params[@]}" "$dest" 2>&1 | grep -q "Server accepts key"; then ssh "${ssh_params[@]}" "$dest" else sshpass -p "$pass" ssh "${ssh_params[@]}" "$dest"