commit c597ba4fece7aed93480ade3a4b8e53acbf6aa2c parent f9b5e90742ccde996cd4ff6e649d483b88b503a7 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Sun, 7 Jun 2020 17:50:24 +0200 Add own ssh-copy-id script Diffstat:
A | .local/bin/ssh-copy-id | | | 35 | +++++++++++++++++++++++++++++++++++ |
1 file changed, 35 insertions(+), 0 deletions(-)
diff --git a/.local/bin/ssh-copy-id b/.local/bin/ssh-copy-id @@ -0,0 +1,35 @@ +#!/bin/sh +pubkeyfile="${HOME}/.ssh/id_rsa.pub" +#authkeyfile="${HOME}/.ssh/authorized_keys" + +usage() { + printf 'usage: %s [USER@]HOST ..\n' "${0##*/}" >&2 + printf 'copies ~/.ssh/id_rsa.pub to every HOST\n' >&2 +} + +die() { + printf 'error: %s\n' "$1" >&2 + exit 1 +} + +copy_key() { + # seen in Solene Rapenne's drist + #ssh_params=-o"ControlMaster=auto"" "-o"ControlPath=/tmp/sshid_ssh_%h_%p_%r.sock"" "-o"ControlPersist=1m" + #ssh $ssh_params "${HOME}" "printf '%s\n' $(cat "$pubkeyfile") >> $authkeyfile" + if ! ssh "$1" "mkdir -p \$HOME/.ssh && echo $(cat "$pubkeyfile") >> \$HOME/.ssh/authorized_keys"; then + die "ssh key transfer failed" + fi +} + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +if [ ! -e "$pubkeyfile" ]; then + die "could not read public key file $pubkeyfile" +fi + +for h in "$@"; do + copy_key "$h" +done