From 318a46a5af66c227e4d4c6256e4132b59bc9a37a Mon Sep 17 00:00:00 2001 From: Fazle Arefin Date: Sun, 26 Apr 2020 14:50:47 +1000 Subject: [PATCH] Add new script myssh.sh --- README.md | 6 ++++++ myssh.sh | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 myssh.sh diff --git a/README.md b/README.md index a26c767..4049437 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,12 @@ The `hostid` command lets you see the current hostid. --- +## myssh.sh + +This script can be used instead of the `ssh` command. It tries to ssh to a server using key-based auth, and if fails, copies the key to the server and tries to ssh again. + +--- + ## ssh-copy-id-auto.sh This script let you copy your ssh-key to your servers for passwordless authentication. This script will help you in a situation where you have a thousand servers in which you want to copy your ssh-key. You can use ssh-copy-id command but it will ask you your password a thousand times. Even if you do automate that, ssh-copy-id will copy to one server at a time which is painfully slow for a thousand servers. diff --git a/myssh.sh b/myssh.sh new file mode 100755 index 0000000..90d04df --- /dev/null +++ b/myssh.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Purpose: Tries to ssh to a server using key-based auth, and if fails, copies the key to the server and tries to ssh again +# Author: Fazle Arefin +# +# Depends on: ./ssh-copy-id-auto-multi.sh + +THIS_SCRIPT=$0 +SSH_HOST=$1 + +[ $# -eq 1 ] || exit 100 + +ssh -o PubkeyAuthentication=yes -o PasswordAuthentication=no -o ChallengeResponseAuthentication=no -o KbdInteractiveAuthentication=no $SSH_HOST + +if [ $? -ne 0 ]; then + ./ssh-copy-id-auto-multi.sh $SSH_HOST && $THIS_SCRIPT $SSH_HOST +fi