Skip to content

Commit

Permalink
fix: improve authentication method check
Browse files Browse the repository at this point in the history
  • Loading branch information
DakEnviy committed Jul 24, 2022
1 parent 2225451 commit 837f260
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sshp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

OPENSSL_ENC_FLAGS=("-des3" "-base64" "-pbkdf2")
SSH_META_DIR="$HOME/.ssh/meta"

show_help() {
cat <<EOF
Expand Down Expand Up @@ -40,7 +41,7 @@ add_creds() {
pass="$3"
ident_filepath="$4"

meta_filepath="$HOME/.ssh/meta/$creds_name"
meta_filepath="$SSH_META_DIR/$creds_name"

if [[ -f "$meta_filepath" ]]; then
echo "Credentials $creds_name is already exist" >&2
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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 "$@"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 837f260

Please sign in to comment.