Skip to content

Commit

Permalink
ssh-clone-id
Browse files Browse the repository at this point in the history
  • Loading branch information
biocoderh committed Sep 29, 2023
1 parent 18d71f8 commit 3753dc2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .local/bin/ssh-clone-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

set -e

if [ -z "$1" ] || [ -z "$2" ]; then
cat << EOF
Clone ssh private and public keys to remote host.
Usage: ssh-clone [key] [remote]
Example: ssh-clone .ssh/id_ed25519 [email protected]
EOF
exit 1
fi

KEY_PATH=$(realpath "$1")
KEY_FILE=$(basename "$1")

REMOTE="$2"
REMOTE_KEY_PATH="$HOME/.ssh/$KEY_FILE"
REMOTE_PUBKEY_PATH="$HOME/.ssh/$KEY_FILE.pub"

USER=$(echo "$2" | cut -d "@" -f 1)
HOME=$(ssh "$2" echo ~)

ssh-copy-id -i "$KEY_PATH.pub" "$REMOTE"

scp "$KEY_PATH" "$KEY_PATH.pub" "$REMOTE:$HOME/.ssh/"

CMD='eval $(ssh-agent -s)'
CMD="$CMD ; chmod 400 $REMOTE_KEY_PATH $REMOTE_PUBKEY_PATH"
CMD="$CMD ; ssh-add $REMOTE_KEY_PATH"

ssh -tt -o StrictHostKeyChecking=no "$REMOTE" "$CMD"

0 comments on commit 3753dc2

Please sign in to comment.