Skip to content

Commit

Permalink
Add new script myssh.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
fazlearefin committed Apr 26, 2020
1 parent 333e8e5 commit 318a46a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions myssh.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 318a46a

Please sign in to comment.