Skip to content

Instantly share code, notes, and snippets.

@rjaeckel
Created August 6, 2013 12:55
Show Gist options
  • Save rjaeckel/6164222 to your computer and use it in GitHub Desktop.
Save rjaeckel/6164222 to your computer and use it in GitHub Desktop.
Put the public ssh key file to various remote hosts to use certificate based authentication
#!/bin/bash
if [ $# -eq 0 ]; then
me=$(basename $0)
echo "-> copy the personal rsa key to other machines for certificate based authentication"
echo Usage:
echo "$me [user@]machine [[user@]machine [...]]"
fi
cert_var=_ssh_key_file
cert_var=$USER$cert_var
cert_ext=.pub
cert=${!cert_var}
if [ ! "$cert" ]; then
cert=~/.ssh/id_rsa
echo "using default key $cert"
echo "export $cert_var=/path/to/key/file to override"
fi
pubkey=$cert$cert_ext
if [ ! -f $cert ];then
echo Key-Pair $cert does not exist. Creating...
ssh-keygen -N "" -f $cert
fi
for arg in "$@"; do
echo Machine $arg:
ssh-copy-id -i $pubkey "$arg"
echo --------------------------------
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment