dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

ssh-copy-id (539B)


      1 #!/bin/sh
      2 pubkeyfile="${HOME}/.ssh/id_rsa.pub"
      3 
      4 usage() {
      5 	printf 'usage: %s [USER@]HOST ..\n' "${0##*/}" >&2
      6 	printf 'copies ~/.ssh/id_rsa.pub to every HOST\n' >&2
      7 }
      8 
      9 die() {
     10 	printf 'error: %s\n' "$1" >&2
     11 	exit 1
     12 }
     13 
     14 copy_key() {
     15 	if ! ssh "$1" "mkdir -p \$HOME/.ssh && echo $(cat "$pubkeyfile") >> \$HOME/.ssh/authorized_keys"; then
     16 		die "ssh key transfer failed"
     17 	fi
     18 }
     19 
     20 if [ $# -lt 1 ]; then
     21 	usage
     22 	exit 1
     23 fi
     24 
     25 if [ ! -e "$pubkeyfile" ]; then
     26 	die "could not read public key file $pubkeyfile"
     27 fi
     28 
     29 for h in "$@"; do
     30 	copy_key "$h"
     31 done